本文整理匯總了C#中System.Nullable<T>.Equals方法的典型用法代碼示例。如果您正苦於以下問題:C# Nullable<T>.Equals方法的具體用法?C# Nullable<T>.Equals怎麽用?C# Nullable<T>.Equals使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類System.Nullable<T>
的用法示例。
在下文中一共展示了Nullable<T>.Equals方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。
示例1: Main
// This code example demonstrates the Nullable<T>.Equals
// methods.
using System;
class Sample
{
public static void Main()
{
int? nullInt1 = 100;
int? nullInt2 = 200;
object myObj;
// Determine if two nullable of System.Int32 values are equal.
// The nullable objects have different values.
Console.Write("1) nullInt1 and nullInt2 ");
if (nullInt1.Equals(nullInt2))
Console.Write("are");
else
Console.Write("are not");
Console.WriteLine(" equal.");
// Determine if a nullable of System.Int32 and an object
// are equal. The object contains the boxed value of the
// nullable object.
myObj = (object)nullInt1;
Console.Write("2) nullInt1 and myObj ");
if (nullInt1.Equals(myObj))
Console.Write("are");
else
Console.Write("are not");
Console.WriteLine(" equal.");
}
}
輸出:
1) nullInt1 and nullInt2 are not equal. 2) nullInt1 and myObj are equal.