许明会的计算机技术主页

Language:C,C++,.NET Framework(C#)
Thinking:Design Pattern,Algorithm,WPF,Windows Internals
Database:SQLServer,Oracle,MySQL,PostSQL
IT:MCITP,Exchange,Lync,Virtualization,CCNP

导航

reference and value type

/// <summary>
/// reference type is allocate on HEAP, 
/// the assignment statement just set a pint to the object.
/// the reference object memory collection on app exit!
/// </summary>
using System;
using System.Collections.Generic;

/// <summary>
/// class is reference type; struct is value type
/// </summary>
class /*struct*/ Point
{
    public int X{get;set;}
    public int Y{get;set;}
}

public class MyClass
{
    public static void Main()
    {
        Point p = new Point{X=3,Y=4};
        Point p1 = p;
        p.X=100;    //X=100,Y=4
        Console.WriteLine("X={0},Y={1}",p1.X,p1.Y);
        Console.ReadKey();
    }
}

posted on 2013-05-10 11:40  许明会  阅读(310)  评论(0编辑  收藏  举报