本文整理汇总了C#中Person.GetHashCode方法的典型用法代码示例。如果您正苦于以下问题:C# Person.GetHashCode方法的具体用法?C# Person.GetHashCode怎么用?C# Person.GetHashCode使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Person
的用法示例。
在下文中一共展示了Person.GetHashCode方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: 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);
}
示例2: Main
public static void Main()
{
Console.WriteLine("**** Fun with System.Object ****\n");
Person p1 = new Person();
Console.WriteLine("ToString: {0}", p1.ToString());
Console.WriteLine("ToString: {0}", p1.GetHashCode());
Console.WriteLine("ToString: {0}", p1.GetType());
}
示例3: Main
public static void Main()
{
string s1 = "abc";
string s2 = "abc";
Person p1 = new Person();
Person p2 = new Person();
Console.WriteLine("s1.GetHashCode {0}", s1.GetHashCode());
Console.WriteLine("s2.GetHashCode {0}", s2.GetHashCode());
Console.WriteLine("p1.GetHashCode {0}", p1.GetHashCode());
Console.WriteLine("p2.GetHashCode {0}", p2.GetHashCode());
}
示例4: Main
static void Main(string[] args)
{
Student stu1 = new Student();
Console.WriteLine(stu1.ToShortString());
Console.WriteLine();
stu1.person = new Person("Иван", "Иванов", new DateTime(1995, 06, 23));
stu1.accessGN = 105;
Console.WriteLine(stu1.ToString());
Console.WriteLine();
Exam[] listEx = new Exam[2];
listEx[0] = new Exam("МАТАН", 5, DateTime.Now);
listEx[1] = new Exam("ООП", 5, DateTime.Today);
stu1.AddExams(listEx);
Console.WriteLine(stu1.ToString());
Console.WriteLine();
Person p1 = new Person();
Person p2 = new Person();
Console.WriteLine("Хеш-код 1: " + p1.GetHashCode());
Console.WriteLine("Хеш-код 2: " + p2.GetHashCode());
Console.WriteLine();
Student stud2 = new Student(new Person("Петр", "Петров", new DateTime(1995, 12, 12)), Education.Specialist, 222);
stud2.AddExams(listEx);
Test[] listTest = new Test[3];
listTest[0] = new Test("ИГ ПР", true, DateTime.Now);
listTest[1] = new Test("Социология", false, DateTime.Now);
listTest[2] = new Test("Электротехника", true, DateTime.Now);
stud2.AddTests(listTest);
Console.WriteLine(stud2.ToString());
Console.WriteLine();
string str = stud2.person.ToString();
Console.WriteLine("Значение свойства типа Student: ");
Console.WriteLine(str);
Student stud2Copy = new Student();
stud2Copy = (Student)stud2.DeepCopy();
stud2Copy.AccessName = "Сидор";
stud2Copy.accessGN = 333;
Console.WriteLine(stud2.ToString());
Console.WriteLine();
Console.WriteLine(stud2Copy.ToString());
Console.WriteLine();
stud2Copy.accessGN = 777;
Console.WriteLine();
foreach (Exam ex in stud2Copy.accessExam)
Console.WriteLine(ex.ItemName);
Console.WriteLine();
foreach (Exam ex in stud2Copy.accessExam)
if (ex.Mark > 3)
Console.WriteLine(ex.ItemName);
Console.ReadKey();
}