本文整理汇总了C#中Person.Equals方法的典型用法代码示例。如果您正苦于以下问题:C# Person.Equals方法的具体用法?C# Person.Equals怎么用?C# Person.Equals使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Person
的用法示例。
在下文中一共展示了Person.Equals方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Equality
public void Equality()
{
var person1 = new Person{
ID = "POP1",
FirstName = "Oleg",
LastName = "Popov",
DOB = new DateTime(1981, 2, 12),
YearsInSpace = 45,
Amount = 100,
Description="Wanted to go to the moon"
};
var person2 = new Person{
ID = "POP1",
FirstName = "Egor",
LastName = "Pedorov",
DOB = new DateTime(1982, 5, 2),
YearsInSpace = 4,
Amount = 1000000
};
Assert.IsTrue( person1.Equals(person2) );
person2.ID = "POP2";
Assert.IsFalse(person1.Equals(person2) );
}
示例2: Main
static void Main()
{
// We'll create one Person object ...
Person p1 = new Person("222-22-2222", "Fred");
// ... and maintain two handles on it (p1 and p2).
Person p2 = p1;
// We'll create a second different Person object with exactly the same
// attribute values as the first Person object that we created, and will
// use variable p3 to maintain a handle on this second object.
Person p3 = new Person("222-22-2222", "Fred");
if (p1 == p2) Console.WriteLine("p1 == p2 is true");
if (p1.Equals(p2)) Console.WriteLine("p1.equals(p2) is true");
if (p1 == p3) Console.WriteLine("p1 == p3 is true");
if (p1.Equals(p3)) Console.WriteLine("p1.equals(p3) is true");
char[] c = {'b','o','o'};
String s1 = new String(c);
String s2 = s1;
String s3 = new String(c);
if (s1 == s2) Console.WriteLine("s1 == s2 is true");
if (s1.Equals(s2)) Console.WriteLine("s1.equals(s2) is true");
if (s1 == s3) Console.WriteLine("s1 == s3 is true");
if (s1.Equals(s3)) Console.WriteLine("s1.equals(s3) is true");
}
示例3: Main
static void Main(string[] args)
{
//PhoneCustomer myCustomer = new PhoneCustomer();
//PhoneCustomerStruct myCustomer2 = new PhoneCustomerStruct();
////if (myCustomer2 is ValueType)
////{
//// Console.WriteLine("ValueType:");
////}
////else
////{
//// Console.WriteLine("not ValueType:");
////}
//Console.WriteLine((myCustomer2 is ValueType) ? "ValueType":"NotValType");
Person person1 = new Person { Name = "Petya" , Age = 11};
Person person2 = new Person { Name = "Petya", Age = 22 };
Person person3 = new Person { Name = "Petya", Age = 11 };
Person person4 = person1;
Person person5 = null;
Person person6 = null;
Console.WriteLine(person1.Equals(person2));
Console.WriteLine(person1.Equals(person3));
Console.WriteLine(person4.Equals(person1));
Console.WriteLine("hash:"+person1.GetHashCode());
Console.WriteLine(person2.ToString());
Console.WriteLine(person1==person3);
Console.WriteLine(person1 != person2);
Console.WriteLine(person5 != person6);
}
示例4: TestEquals
public void TestEquals()
{
var person1 = new Person() {FirstName = "DANIEL", LastName = "METZROTH"};
var person2 = new Person() {FirstName = "DANIEL", LastName = "METZROTH"};
Assert.IsTrue(person1.Equals(person2));
person2.LastName = "BOND";
Assert.IsFalse(person1.Equals(person2));
person2.FirstName = "JAMES";
person2.LastName = "METZROTH";
Assert.IsFalse(person1.Equals(person2));
}
示例5: Main
static void Main(string[] args)
{
var weko1 = new Person { ID = 1, FirstName = "Wekoslav", LastName = "Stefanovski" };
var weko2 = new Person { ID = 2, FirstName = "Wekoslav", LastName = "Stefanovski" };
Console.WriteLine(weko1.Equals(weko2));
}
示例6: Main
private static void Main()
{
byte[] bytes;
// Create a new person
Person person = new Person
{
Id = 1,
Name = "Foo",
Email = "[email protected]",
Phones = { new Person.Types.PhoneNumber { Number = "555-1212" } }
};
using (MemoryStream stream = new MemoryStream())
{
// Save the person to a stream
person.WriteTo(stream);
bytes = stream.ToArray();
}
Person copy = Person.Parser.ParseFrom(bytes);
AddressBook book = new AddressBook
{
People = { copy }
};
bytes = book.ToByteArray();
// And read the address book back again
AddressBook restored = AddressBook.Parser.ParseFrom(bytes);
// The message performs a deep-comparison on equality:
if (restored.People.Count != 1 || !person.Equals(restored.People[0]))
{
throw new Exception("There is a bad person in here!");
}
}
示例7: Main
public static void Main()
{
var p1 = new Person();
p1.FirstName = "John";
var p2 = new Person();
p2.FirstName = "John";
Console.WriteLine("p1 = p2: {0}", p1.Equals(p2));
}
示例8: Main
static void Main()
{
// Create a new Person on the stack
Person p1 = new Person("Bob");
// p2 is a separate copy of p1
Person p2 = p1;
// Change name of p2
p2.Name = "Alice";
// p1’s name is still Bob
if (p1.Name == "Bob") Console.WriteLine("passed");
// p1 and p2 point to different objects
if (!p1.Equals(p2)) Console.WriteLine("passed");
}
示例9: TestEquals
public void TestEquals()
{
var original = new Person("Wes", "Montgomery");
var copy = new Person("Wes", "Montgomery");
Assert.IsTrue(original.Equals(copy));
}
示例10: ConsumerConsumesAuthorPerson
public void ConsumerConsumesAuthorPerson(XElement documentXEl, Person expected)
{
DocumentMetadata doc = XDMetadataConsumer.ConsumeDocument(documentXEl);
Assert.Equal(expected.ToString(), doc.Author.Person.ToString());
Assert.True(expected.Equals(doc.Author.Person));
}
示例11: TestEquals
public void TestEquals()
{
string stringTest = "foo bar";
uint numericTest = 3;
Person three = new Person(3);
Person four = new Person(4);
Person threeAgain = new Person(3);
Product threeProduct = new Product(3);
Assert.IsFalse(three.Equals(stringTest), "Entity does not equal a string");
Assert.IsFalse(three.Equals(numericTest), "Entity does not equal a uint");
Assert.IsFalse(three.Equals(four), "Non-matching identities not equal");
Assert.IsTrue(three.Equals(three), "Copies of the same object are equal");
Assert.IsTrue(three.Equals(threeAgain), "Identical identities are equal");
Assert.IsFalse(three.Equals(threeProduct), "Non-matching types not equal");
}
示例12: Remove
/* Private helper methods */
private void Remove(Person person, IList<Person> personList)
{
int i = 0;
while(i<personList.Count){
Person item = personList[i];
if (person.Equals(item)) personList.Remove(item);
else i++;
}
}
示例13: NameEquals
public void NameEquals()
{
Person p1 = new Person { First = "Bob", Last = "Smith" };
Person p2 = new Person { First = "Bob", Last = "Smith" };
Assert.True(p1.Equals(p2));
}