1.5.txt
来自「《Microsoft Visual C# .NET 2003开发技巧大全》源代码」· 文本 代码 · 共 39 行
TXT
39 行
Listing 1.5 Using Relational Operators on Value and Reference Types
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 );
// compare 2 objects which contains overloaded == operator
string c = “hello”;
string d = “hello”;
Console.WriteLine( (object) c==(object) d );
// compare 2 objects for equality
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;
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?