📄 1.5.txt
字号:
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 + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -