本文整理汇总了C#中System.Equals方法的典型用法代码示例。如果您正苦于以下问题:C# System.Equals方法的具体用法?C# System.Equals怎么用?C# System.Equals使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System
的用法示例。
在下文中一共展示了System.Equals方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: checkCode
} //end method
/// <summary> Checks a code for an exact match, and using certain sequences where some
/// characters are wildcards (e.g. HL7nnnn). If the pattern contains one of
/// " or ", " OR ", or "," each operand is checked.
/// </summary>
private bool checkCode(System.String code, System.String pattern)
{
bool match = false;
//mod by Neal acharya - Do full match on with the pattern. If code matches pattern then return true
//else parse pattern to look for wildcard characters
if (code.Equals(pattern))
{
match = true;
}
//end if
else
{
if (pattern.IndexOf(' ') >= 0 || pattern.IndexOf(',') >= 0)
{
SupportClass.Tokenizer tok = new SupportClass.Tokenizer(pattern, ", ", false);
while (tok.HasMoreTokens() && !match)
{
System.String t = tok.NextToken();
if (!t.ToUpper().Equals("or".ToUpper()))
match = checkCode(code, t);
} //end while
}
//end if
else
{
if (code.Equals(pattern))
{
match = true;
}
} //end else
} //end else
return match;
} //end method
示例2: Main_12_2_3
//Main_12_2_3
public static void Main_12_2_3()
{
//User user = new User { Name = "小王", Age = 27 };
var user = new { Name = "小王", Age = 27 };
var my = new { Name = "Wang", Emal = "[email protected]" };
//等效于User v = new User { Name = "小王", Age = 27 };
Console.WriteLine(user.Name);
Console.WriteLine(user.GetType());
var name = "小王";
var age = 27;
//等效于string v2 = "123";
Console.WriteLine(name.GetType());
Console.WriteLine(age.GetType());
//创建不同的Type
var v1 = new { Name = "Aero", Age = 27 };
var v2 = new { Name = "Emma", Age = 22 };
var v3 = new { Age = 27, Name = "Aero" };
Console.WriteLine(v1.Equals(v2));
Console.WriteLine(v1.Equals(v3));
Console.WriteLine(ReferenceEquals(v1.GetType(), v2.GetType()));
Console.WriteLine(ReferenceEquals(v1.GetType(), v3.GetType()));
}
示例3: AnonymousTypesMain
public static void AnonymousTypesMain()
{
// create a "person" object using an anonymous type
var bob = new { Name = "Bob Smith", Age = 37 };
// display bob's information
Console.WriteLine( "Bob: " + bob.ToString() );
// create another "person" object using the same anonymous type
var steve = new { Name = "Steve Jones", Age = 26 };
// display steve's information
Console.WriteLine( "Steve: " + steve.ToString() );
// determine if objects of the same anonymous type are equal
Console.WriteLine( "\nBob and Steve are {0}",
( bob.Equals( steve ) ? "equal" : "not equal" ) );
// create a "person" object using an anonymous type
var bob2 = new { Name = "Bob Smith", Age = 37 };
// display the bob's information
Console.WriteLine( "\nBob2: " + bob2.ToString() );
// determine whether objects of the same anonymous type are equal
Console.WriteLine( "\nBob and Bob2 are {0}\n",
( bob.Equals( bob2 ) ? "equal" : "not equal" ) );
}
示例4: Accept
public virtual FieldSelectorResult Accept(System.String fieldName)
{
if (fieldName.Equals(DocHelper.TEXT_FIELD_1_KEY) || fieldName.Equals(DocHelper.LAZY_FIELD_BINARY_KEY))
return FieldSelectorResult.SIZE;
else if (fieldName.Equals(DocHelper.TEXT_FIELD_3_KEY))
return FieldSelectorResult.LOAD;
else
return FieldSelectorResult.NO_LOAD;
}
示例5: test
/// <summary> Empty string, null, and the HL7 explicit null (two double-quotes) are passed.
///
/// </summary>
/// <seealso cref="Genetibase.NuGenHL7.validation.PrimitiveTypeRule.test(java.lang.String)">
/// </seealso>
public virtual bool test(System.String value_Renamed)
{
if (value_Renamed == null || value_Renamed.Equals("\"\"") || value_Renamed.Equals(""))
{
return true;
}
else
{
return Regex.IsMatch(value_Renamed, matchString);
}
}
示例6: Accept
/* (non-Javadoc)
* @see java.io.FilenameFilter#accept(java.io.File, java.lang.String)
*/
public virtual bool Accept(System.IO.FileInfo dir, System.String name)
{
for (int i = 0; i < IndexFileNames.INDEX_EXTENSIONS.Length; i++)
{
if (name.EndsWith("." + IndexFileNames.INDEX_EXTENSIONS[i]))
return true;
}
if (name.Equals(IndexFileNames.DELETABLE))
return true;
else if (name.Equals(IndexFileNames.SEGMENTS))
return true;
else return true; // else if (name.Matches(".+\\.f\\d+")) // {{Aroush-1.9}}
// return false;
}
示例7: IsNull
public static void IsNull(System.Object argument, string argumentName)
{
if (argument == null || argument.Equals(null))
{
throw new ArgumentNullException(argumentName);
}
}
示例8: Main
public static void Main()
{
var myCar = new { Color = "Red", Brand = "BMW", Speed = 180 };
Console.WriteLine("My car is a {0} {1}.", myCar.Color, myCar.Brand);
Console.WriteLine("It runs {0} km/h.", myCar.Speed);
Console.WriteLine();
var p = new { X = 3, Y = 5 };
var q = new { X = 3, Y = 5 };
Console.WriteLine(p);
Console.WriteLine(q);
Console.WriteLine(p == q); // false
Console.WriteLine(p.Equals(q)); // true
Console.WriteLine();
var combined = new { P = p, Q = q };
Console.WriteLine(combined.P.X);
Console.WriteLine();
var arr = new[]
{
new { X = 3, Y = 5 },
new { X = 1, Y = 2 },
new { X = 0, Y = 7 }
};
foreach (var item in arr)
{
Console.WriteLine("({0}, {1})", item.X, item.Y);
}
}
示例9: EqualityTest
static void EqualityTest()
{
// Make 2 anonymous classes with identical name/value pairs.
var firstCar = new { Color = "Bright Pink", Make = "Saab", CurrentSpeed = 55 };
var secondCar = new { Color = "Bright Pink", Make = "Saab", CurrentSpeed = 55 };
// Are they considered equal when using Equals()?
if (firstCar.Equals(secondCar))
Console.WriteLine("Same anonymous object!");
else
Console.WriteLine("Not the same anonymous object!");
// Are they considered equal when using ==?
if (firstCar == secondCar)
Console.WriteLine("Same anonymous object!");
else
Console.WriteLine("Not the same anonymous object!");
// Are these objects the same underlying type?
if (firstCar.GetType().Name == secondCar.GetType().Name)
Console.WriteLine("We are both the same type!");
else
Console.WriteLine("We are different types!");
// Show all the details.
Console.WriteLine();
ReflectOverAnonymousType(firstCar);
ReflectOverAnonymousType(secondCar);
}
示例10: EqualityTest
public static void EqualityTest()
{
// Make 2 anonymous classes with identical name/value pairs.
var firstProduct = new { Color = "Blue", Name = "Widget", RetailPrice = 55 };
var secondProduct = new { Color = "Blue", Name = "Widget", RetailPrice = 55 };
// Are they considered equal when using Equals()?
if (firstProduct.Equals(secondProduct))
Console.WriteLine("Same anonymous object!");
else
Console.WriteLine("Not the same anonymous object!");
// Are they considered equal when using ==?
if (firstProduct == secondProduct)
Console.WriteLine("Same anonymous object!");
else
Console.WriteLine("Not the same anonymous object!");
// Are these objects the same underlying type?
if (firstProduct.GetType().Name == secondProduct.GetType().Name)
Console.WriteLine("We are both the same type!");
else
Console.WriteLine("We are different types!");
// Show all the details.
Console.WriteLine();
ReflectOverAnonymousType(firstProduct);
ReflectOverAnonymousType(secondProduct);
}
示例11: Main
static void Main(string[] args)
{
Console.WriteLine("***** Fun with Anonymous Types *****\n");
// Make an anonymous type representing a car.
var myCar = new { Color = "Bright Pink", Make = "Saab", CurrentSpeed = 55 };
// Now show the color and make.
Console.WriteLine("My car is a {0} {1}.", myCar.Color, myCar.Make);
// Now call our helper method to build anonymous type via args.
BuildAnonType("BMW", "Black", 90);
Console.ReadLine();
ReflectOverAnonymousType(myCar);
// Make 2 anonymous classes with identical name/value pairs.
var firstCar = new { Color = "Bright Pink", Make = "Saab", CurrentSpeed = 55 };
var secondCar = new { Color = "Bright Pink", Make = "Saab", CurrentSpeed = 55 };
// Are they considered equal when using Equals()?
if (firstCar.Equals(secondCar))
Console.WriteLine("Same anonymous object!");
else
Console.WriteLine("Not the same anonymous object!");
// Are they considered equal when using ==?
if (firstCar == secondCar)
Console.WriteLine("Same anonymous object!");
else
Console.WriteLine("Not the same anonymous object!");
// Are these objects the same underlying type?
if (firstCar.GetType().Name == secondCar.GetType().Name)
Console.WriteLine("We are both the same type!");
else
Console.WriteLine("We are different types!");
}
示例12: Accept
/* (non-Javadoc)
* @see java.io.FilenameFilter#accept(java.io.File, java.lang.String)
*/
public virtual bool Accept(System.IO.FileInfo dir, System.String name)
{
int i = name.LastIndexOf((System.Char) '.');
if (i != - 1)
{
System.String extension = name.Substring(1 + i);
if (extensions.Contains(extension))
{
return true;
}
else if (extension.StartsWith("f") && (new System.Text.RegularExpressions.Regex("f\\d+")).Match(extension).Success)
{
return true;
}
else if (extension.StartsWith("s") && (new System.Text.RegularExpressions.Regex("s\\d+")).Match(extension).Success)
{
return true;
}
}
else
{
if (name.Equals(IndexFileNames.DELETABLE))
return true;
else if (name.StartsWith(IndexFileNames.SEGMENTS))
return true;
}
return false;
}
示例13: Main
static void Main(string[] args)
{
var firstCar = new { Color = "Bright Pink", Make = "Saab", CurrentSpeed = 55};
var SecondCar = new { Color = "Bright Pin", Make = "Saab", CurrentSpeed = 55 };
// 匿名类型重写的Equals()是基于值类型的实现
if (firstCar.Equals(SecondCar))
{
Console.WriteLine("Equals 是相等的");
}
else
{
Console.WriteLine("Equals 是不相等的");
}
// 因为匿名对象没有重写C#的相等操作符(==和!=)所以直接比较引用,
//即这两个引用是不是指向同一个对象
// 如果重载==和!= 应该调用已经重写了的Equals()
if (firstCar == SecondCar)
{
Console.WriteLine("refer to the same object");
}
else
{
Console.WriteLine("Refer to the different object");
}
if (firstCar.GetType().Name == SecondCar.GetType().Name)
{
Console.WriteLine("一个类的两个对象");
}
}
示例14: Main
static void Main(string[] args)
{
string dada = "the quick brown fox jump over the fence";
Console.WriteLine(dada.WordCount());
Console.WriteLine(Eext.WordCount(dada));
List<int> ints = new List<int> { 1, 2, 4, 6, 2, 6, };
foreach (var item in ints)
{
Console.Write("{0}, ", item);
}
ints.IncreaseWith(100);
Console.WriteLine();
foreach (var item in ints)
{
Console.Write("{0}, ", item);
}
Console.WriteLine();
var point = new { X = 3, Y = 5 };
var secondPpoint = new { X = 4, Y = 5 };
Console.WriteLine(point.Equals(secondPpoint));
Console.WriteLine(point.X);
Console.WriteLine(point);
int senek = 12;
Console.WriteLine(Eext.IncrWithOne(senek));
Console.WriteLine(senek.IncrWithOne());
}
示例15: Main
static void Main(string[] args)
{
//定义两个相同的匿名类型
var Book1 = new { BookName = "ASP.NET 4.0 程序设计", ISBN = "123456789", Price = 59.8 };
var Book2 = new { BookName = "ASP.NET 4.0 程序设计", ISBN = "123456789", Price = 59.8 };
//使用重载的Equals方法进行两个匿名类型的等值比较
if (Book1.Equals(Book2))
{
Console.WriteLine("两个匿名类型完全相等!");
}
else
{
Console.WriteLine("两个匿名类型不相等!");
}
//使用C#的==操作符进行两个类型的比较
if (Book1==Book2)
{
Console.WriteLine("两个匿名类型完全相等!");
}
else
{
Console.WriteLine("两个匿名类型不相等!");
}
//查看Book1和Book2这两个匿名类型的内部信息
GetAnonymousTypesInfo(Book1);
GetAnonymousTypesInfo(Book2);
}