using System;
namespace _10_Relations
{
/// <summary>
/// Summary description for Class1.
/// </summary>
class ComparingRelations
{
/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main(string[] args)
{
// compare 2 values for equality
int a = 12;
int b = 12;
Console.WriteLine( a == b );
Console.WriteLine( (object)a == (object)b );
// a与b不相等是因为a与b都是值类型,本身存储相关数据
string c = "hello";
string d = "hello";
Console.WriteLine( (object) c==(object) d );
// c与d不相等是因为string c与d都是reference类型,存储的都是相同的静态字符数组的地址
ClassCompare x = new ClassCompare();
ClassCompare y;
x.val = 1;
y = x;
Console.WriteLine( x == y );
// changing 1 object also changes the other
x.val = 2;
Console.WriteLine( y.val.ToString() );
}
}
class ClassCompare
{
public int val = 0;
}
}


浙公网安备 33010602011771号