/// <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();
    }
}

相关文章:

  • 2021-06-13
  • 2021-11-23
  • 2021-08-04
  • 2022-12-23
  • 2021-07-12
  • 2021-10-17
猜你喜欢
  • 2022-12-23
  • 2021-09-07
  • 2021-09-09
  • 2021-09-14
  • 2022-03-07
  • 2021-06-17
  • 2021-06-25
相关资源
相似解决方案