本文整理汇总了C#中Student.GetHashCode方法的典型用法代码示例。如果您正苦于以下问题:C# Student.GetHashCode方法的具体用法?C# Student.GetHashCode怎么用?C# Student.GetHashCode使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Student
的用法示例。
在下文中一共展示了Student.GetHashCode方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Main
static void Main()
{
Student Kiritakcho = new Student("Kiritakcho", "Muffof", "Shmindel",12314213);
Student Harabakcho = new Student("Harabakcho", "Hold ma pudel", "La Bamba", 12314214);
Harabakcho.University = University.TU;
Harabakcho.Specialty = Specialty.Hardware;
Harabakcho.Faculty = Faculty.Phisics;
//printing info
Console.WriteLine(Kiritakcho);
Console.WriteLine(Harabakcho);
Console.WriteLine("Are Kiritakcho and Harabakcho realy one person: ");
Console.WriteLine(Kiritakcho == Harabakcho);
Console.WriteLine("Get Harabakcho`s Hash Code please: {0}", Harabakcho.GetHashCode());
Console.WriteLine();
//cloning Harabakcho and modeling it to version TWO
var HarabakTwo = Harabakcho.Clone();
HarabakTwo.FirstName = "HarabakTwo";
Console.WriteLine(HarabakTwo);
//comparing the three students, for better understanding change names
Console.WriteLine(Harabakcho.CompareTo(Kiritakcho)); // La Bamba is before Shmindel, so it returns -1
Console.WriteLine(HarabakTwo.CompareTo(Harabakcho)); // HarabakTwo is after HarabakCHO, so it returns 1
}
示例2: Main
static void Main()
{
Student georgiStudent = new Student("Georgi", "Ivanov", "Petrov", 12345678, "Sofia, ul.Oborishte 15", "+359888777666",
"[email protected]", 2, University.SU, Faculty.FMI, Speciality.AppliedMathematics);
Console.WriteLine(georgiStudent);
Console.WriteLine();
Student ivanStudent = new Student("Ivan", "Ivanov", "Georgiev", 12345679, "Plovdiv, ul.Trakia 18", "+359888777555",
"[email protected]", 2, University.UACEG, Faculty.FacultyOfStructuralEngineering, Speciality.StructuralEngineering);
Console.WriteLine(ivanStudent);
Student georgiStudentTwo = new Student("Georgi", "Ivanov", "Petrov", 123456799, "Sofia, ul.Oborishte 15", "+359888777666",
"[email protected]", 2, University.SU, Faculty.FMI, Speciality.AppliedMathematics);
Console.WriteLine(georgiStudent);
Console.WriteLine();
Console.WriteLine(georgiStudent.Equals(ivanStudent));
Console.WriteLine(georgiStudent == georgiStudentTwo); //това трябва да е True
Console.WriteLine(georgiStudent != georgiStudentTwo); //това трябва да е False
Console.WriteLine(georgiStudent.GetHashCode());
Console.WriteLine(ivanStudent.GetHashCode());
Student ivanCloning = (Student)ivanStudent.Clone();
Console.WriteLine(ivanCloning);
Console.WriteLine(georgiStudent.CompareTo(ivanStudent)); //-1, т.е. georgiStudent е пред ivanStudent в подреждането/сравнението
Console.WriteLine(ivanStudent.CompareTo(ivanCloning)); //0
}
示例3: Main
public static void Main()
{
Student firstStudent = new Student("Pesho", "Georgiev", "Ivanov", "Sofia", "+3849384398",
"[email protected]", 3122, Specialties.Telecommunications, Universities.TU, Faculties.Law);
Student secondStudent = new Student("Dancho", "Ivanov", "Petrov", "Plovdiv", "039483439",
"[email protected]", 23453, Specialties.IT, Universities.NBU, Faculties.Mathematics);
Console.WriteLine("First student HashCode: " + firstStudent.GetHashCode());
Console.WriteLine("Second student HashCode: " + secondStudent.GetHashCode());
Console.WriteLine("First student equals second student: " + firstStudent.Equals(secondStudent));
Console.WriteLine("First student == second student: " + (firstStudent == secondStudent));
Console.WriteLine("First student != second student: " + (firstStudent != secondStudent));
Console.WriteLine();
Console.WriteLine(secondStudent.ToString());
Console.WriteLine();
Student thirdStudent = (Student)secondStudent.Clone();
Console.WriteLine("Second student == third student: " + (secondStudent == thirdStudent));
Console.WriteLine("Second student != third student: " + (secondStudent != thirdStudent));
Console.WriteLine("Second student.CompareTo(third student): " + secondStudent.CompareTo(thirdStudent));
Console.WriteLine("First student.CompareTo(Second student): " + firstStudent.CompareTo(secondStudent));
Console.WriteLine(firstStudent.ToString());
Console.WriteLine(secondStudent.ToString());
Console.WriteLine(thirdStudent.ToString());
}
示例4: Main
static void Main()
{
//int res = "Atanas".CompareTo("Branimir");
Student equalStud1 = new Student("Pesho", "Georgiev", "Stratiev", 215677, "Sofia 1440, str.Todor Aleksandrov #12", "[email protected]", "0895623333", "OOP", Speciality.Programing, Univercity.TelerikAcademy, Faculty.InforamtionScience);
Student equalStud2 = new Student("Pesho", "Ivanov", "Stratiev", 215677, "Sofia 3215, bul.Goce Delchev #16", "[email protected]", "0825953378", "UIDesign", Speciality.Mobiletechnologies, Univercity.TelerikAcademy, Faculty.InforamtionScience);
Console.WriteLine(equalStud1);
Console.WriteLine("Hash code of {1}: {0}", equalStud1.GetHashCode(), equalStud1.PfirstName);
Console.WriteLine("\n{0}", equalStud2);
Console.WriteLine("Hash code of {0}: {1}", equalStud2.PfirstName, equalStud2.GetHashCode());
Console.WriteLine("---------\nAre students equal: " + equalStud1.Equals(equalStud2) + "\n"); // true
Student diffStud1 = new Student("Evlogi", "Ivanov", "Hristov", 215677, "Munchen , blv.Hainz", "[email protected]", "+034525234", "OOP", Speciality.Infomationtechnologies, Univercity.SoftwareAcademy, Faculty.InforamtionScience);
Student diffStud2 = new Student("Nikolay", "Ivanov", "Kostov", 215677, "Sofia 1440, str.Aleksander Malinov", "[email protected]", "0875723731", "OOP", Speciality.ComputerScince, Univercity.TelerikAcademy, Faculty.InforamtionScience);
Console.WriteLine("Comparing new students: {0} and {1}\n Result: {2}", diffStud1.PfirstName, diffStud2.PfirstName, diffStud2.Equals(diffStud1));
Console.WriteLine("{0} == {1} : {2} \n{0} != {1} : {3}", diffStud1.PfirstName, diffStud2.PfirstName, diffStud1 == diffStud2 ,diffStud1 != diffStud2);
//Cloning
Console.WriteLine("\n----Try to clone----\n");
// Change setting to copied object and then compare them
var fullCopyofStudent = (Student)diffStud1.Clone();
Console.WriteLine("Comparing new object with old: {0}\n", fullCopyofStudent == diffStud1);
fullCopyofStudent.PfirstName = "Doncho"; // Important !!! Changing name ...
Console.WriteLine("Change first name to new obj. Are they equals: {0}\n Answer: newObj.FirstName = {1}\n\t oldObj2.FirstName = {2}", fullCopyofStudent == diffStud1 , fullCopyofStudent.PfirstName , diffStud1.PfirstName);
//Comparing
Console.WriteLine("\n----Try to compare----\n");
ComparingObjs(equalStud1.CompareTo(equalStud2)); // equalStud1 & equalStud2;
ComparingObjs(diffStud1.CompareTo(diffStud2)); //diffStud1 & diffStud2
ComparingObjs(equalStud2.CompareTo(fullCopyofStudent)); // equalStud2 & fullCopyofStudent
}
示例5: Main
internal static void Main()
{
// Task 1:
// Define a class Student, which contains data about a student.
// Override the standard methods, inherited by System.Object:
// Equals(), ToString(), GetHashCode() and operators == and !=.
Student stu1 = new Student("Billy", "Bob", 2939025702, University.Stanford, Faculty.Engineering, Specialty.ComputerScience);
Student stu2 = new Student("John", "Chambers", 6536025741, University.Harvard, Faculty.Business, Specialty.Management);
Console.WriteLine("stu1: {0}", stu1);
Console.WriteLine("stu2: {0}", stu2);
Console.WriteLine("stu1 hash code: {0}", stu1.GetHashCode());
Console.WriteLine("stu2 hash code: {0}", stu2.GetHashCode());
Console.WriteLine("stu1 == stu2 -> {0}", stu1 == stu2);
Console.WriteLine("stu1 != stu2 -> {0}", stu1 != stu2);
Console.WriteLine("stu1.Equals(stu2) -> {0}", stu1.Equals(stu2));
// Task 2: Clone
Student stu3 = (Student)stu1.Clone();
Console.WriteLine("stu1 clone: {0}", stu3);
// Task 3: Compare
Console.WriteLine("stu1 > stu2 -> {0}", stu1.CompareTo(stu2));
Console.WriteLine("stu1 > stu3 -> {0}", stu1.CompareTo(stu3));
}
示例6: Main
static void Main(string[] args)
{
Student firstStudent = new Student("Ivan", "Georgiev", "Petrov", 543943113, "Sofia", "+359854332356",
"[email protected]", 3, Specialties.ComputerScience, Faculties.FMI, Universities.SU);
Student secondStudent = new Student("Todor", "Dimitrov", "Hristov", 7643265123, "Sofia", "+359834651209",
"[email protected]", 3, Specialties.ComputerScience, Faculties.FMI, Universities.SU);
Console.WriteLine(firstStudent);
Console.WriteLine(secondStudent);
Console.WriteLine(firstStudent.GetHashCode());
Console.WriteLine(secondStudent.GetHashCode());
Console.WriteLine();
Console.WriteLine(firstStudent.Equals(secondStudent));
Console.WriteLine(firstStudent == secondStudent);
Console.WriteLine(firstStudent != secondStudent);
Console.WriteLine();
Student studentClone = (Student)firstStudent.Clone();
Console.WriteLine(firstStudent.Equals(studentClone));
Console.WriteLine(firstStudent == studentClone);
Console.WriteLine(firstStudent != studentClone);
Console.WriteLine();
}
示例7: Main
static void Main()
{
Student studOne = new Student("Nikolai", "Iliev", "Kirilov", 8741, "Sofiq", 0884125741, "[email protected]", 3,
Specialty.Telecommunications, University.SU, Faculty.Telecommunications);
Student studTwo = new Student("Stanislav", "Krasimirov", "Ivanov", 2478, "Varna", 0894715687, "[email protected]", 1,
Specialty.Mathematics, University.VINS, Faculty.Mathematics);
Student studThree = new Student("Nikolai", "Iliev", "Kirilov", 8741, "Sofiq", 0884125741, "[email protected]", 3,
Specialty.ArtsOfMarketing, University.VINS, Faculty.Business);
Console.ForegroundColor = ConsoleColor.Green;
Console.WriteLine("StudOne equal StudTwo: {0}" , studOne.Equals(studTwo));
Console.WriteLine("StudOne equal StudThree: {0}", studOne.Equals(studThree));
Console.WriteLine();
Console.WriteLine("StudOne == StudTwo: {0}", studOne == studTwo);
Console.WriteLine("StudOne == StudThree: {0}", studOne == studThree);
Console.WriteLine();
Console.WriteLine("StudOne HashCode: {0}", studOne.GetHashCode());
Console.WriteLine("StudTwo HashCode: {0}", studTwo.GetHashCode());
Console.WriteLine();
Console.WriteLine("StudOne Deep Clone in StudFour...");
Student studFour = studOne.Clone();
Console.WriteLine();
Console.WriteLine("Print StudFour: ");
Console.ResetColor();
Console.WriteLine(studFour);
Console.ForegroundColor = ConsoleColor.Green;
Console.WriteLine("StudOne compare to StudTwo: {0}", studOne.CompareTo(studTwo));
}
示例8: Main
public static void Main()
{
Student pesho1 = new Student("Pesho", "Petrov", "Ivanov", "123456789");
Student pesho2 = new Student("Pesho", "Petrov", "Ivanov", "111111111");
Console.WriteLine(pesho1);
Console.WriteLine(pesho2);
Console.WriteLine("They are equals?");
// Equals
if (pesho1.Equals(pesho2))
Console.WriteLine(true);
else
Console.WriteLine(false);
// ==
if (pesho1 == pesho2)
Console.WriteLine(true);
else
Console.WriteLine(false);
Console.WriteLine("Pesho1 HashCode: {0}", pesho1.GetHashCode());
Console.WriteLine("Pesho2 HashCode: {0}", pesho2.GetHashCode());
Console.WriteLine();
var peshoClone = pesho1.Clone();
Console.WriteLine(peshoClone);
}
示例9: Main
static void Main()
{
Student pesho = new Student("Pesho", "Peshev", "Peshev", 10025030, "Mladost 1", "+359888777222", "[email protected]", 2, Specialty.Engineering, University.TU, Faculty.FEn);
Student gosho = new Student("Gosho", "Goshev", "Goshev", 10030020, "Druzhba 2", "0888500300", "[email protected]", 3, Specialty.Informatics, University.SofiaUniversity, Faculty.FI);
Console.WriteLine(new string('-',50));
Console.WriteLine("Getting hashcodes: ");
Console.WriteLine(pesho.GetHashCode());
Console.WriteLine(gosho.GetHashCode());
Console.WriteLine(new string('-', 50));
Console.WriteLine(pesho);
Console.WriteLine(gosho);
Console.WriteLine(new string('-', 50));
Console.WriteLine("Is pesho equal to gosho?");
Console.WriteLine(pesho.Equals(gosho));
Console.WriteLine(pesho==gosho);
Console.WriteLine("Is pesho different from gosho?");
Console.WriteLine(pesho!=gosho);
Console.WriteLine(new string('-', 50));
Student pesho1 = pesho.Clone() as Student;
Console.WriteLine(pesho1);
Console.WriteLine(new string('-', 50));
Console.WriteLine(pesho.CompareTo(gosho));
Console.WriteLine(gosho.CompareTo(pesho));
Console.WriteLine(pesho.CompareTo(pesho1));
}
示例10: Main
static void Main()
{
Student s1 = new Student("Borislav", "Borisov", 6004399);
Console.WriteLine(s1.ToString());
Student s2 = new Student("Ivan", "Borisov", 600123);
//Hashcode of student 1
Console.WriteLine(s2.GetHashCode());
//Doing shadow clone of s1
Student s3 = (Student)s1.Clone();
s3.FirstName = "Robert";
Console.WriteLine(s1.ToString());
Console.WriteLine(s3.ToString());
int result = s1.CompareTo(s3);
if (result < 0)
{
Console.WriteLine("s1 is smaller");
}
else if (result > 0)
{
Console.WriteLine("s2 is smaller");
}
else
{
Console.WriteLine("they are equal");
}
Console.WriteLine(s1 == s2);
}
示例11: Main
static void Main()
{
Student st1 = new Student("Dimitar", "Ivanov", "Georgiev", 123546434, "Stud grad bl 42", "+359 888 235214", "[email protected]", 2,
University.UNSS, Faculty.Stopanski, Specialty.Marketing);
Student st2 = new Student();
// Test Student.equals
Console.WriteLine(st1.Equals(st2));
// Test Student operator == !=
if (st1!=st2)
{
Console.WriteLine("Studen1 is different than Student2");
}
// Test Student.GetHashCode()
Console.WriteLine("HashCode of Student1 is {0}", st1.GetHashCode());
Console.WriteLine();
Console.WriteLine(st1);
// Test student.Clone()
st2 = st1.Clone();
// Test Student operator == !=
if (st1==st2)
{
Console.WriteLine("Now the both students are equal");
}
// Test if the clone methods performs deep clonning
st2.Facult = Faculty.Informatika;
st2.FirstName = "Nedjalko";
st2.Course = 4;
st2.SSN = 65467616;
Console.WriteLine();
Console.WriteLine("Student 1: {0}", st1);
Console.WriteLine();
Console.WriteLine("Student 2: {0}", st2);
Student st3 = st2.Clone();
st3.MiddleName = "Yankov";
st3.SSN = 54674751;
Student st4 = st3.Clone();
st4.SSN = 24674751;
Student[] myArray = { st4, st2, st1, st3};
// Test Student.CopmareTo method
Array.Sort(myArray);
Console.WriteLine();
Console.WriteLine();
Console.WriteLine("Sorted students are:");
foreach (Student item in myArray)
{
Console.WriteLine();
Console.WriteLine(item);
}
}
示例12: Main
static void Main()
{
Student firstStudent = new Student("Pesho", "Petrov", "Georgiev", 123456789,
"PeshoStreet 5", 0885132669, "[email protected]", 1, University.TU_Sofia,
Faculty.FacultyOfGermanEngineering, Specialty.ComputerSystemsAndTechnology);
Student secondStudent = new Student("Pesho", "Petrov", "Georgiev", 987654321,
"PeshoStreet 7", 0887785764, "[email protected]", 1, University.TU_Sofia,
Faculty.FacultyOfGermanEngineering, Specialty.ComputerSystemsAndTechnology);
Student thirdStudent = new Student("Gosho", "Petrov", "Georgiev", 987654321,
"PeshoStreet 7", 0885985764, "[email protected]", 1, University.TU_Sofia,
Faculty.FacultyOfGermanEngineering, Specialty.ComputerSystemsAndTechnology);
Student fourthStudent = new Student("Gosho", "Petrov", "Georgiev", 987654321,
"PeshoStreet 7", 0885985764, "[email protected]", 1, University.SofiaUniversity,
Faculty.FacultyOfMathematicsAndInformatics, Specialty.SoftwareEngineering);
Console.WriteLine(firstStudent);
if (firstStudent == secondStudent)
{
Console.WriteLine("The first student matches the second!");
}
if (thirdStudent == secondStudent)
{
Console.WriteLine("The second student matches the third!");
}
if (thirdStudent == fourthStudent)
{
Console.WriteLine("The third student matches the fourth!");
}
if (firstStudent != fourthStudent)
{
Console.WriteLine("The first student doesn't match the fourth!");
}
Console.WriteLine();
Console.WriteLine(firstStudent.GetHashCode()); //collision
Console.WriteLine(secondStudent.GetHashCode()); //collision
Console.WriteLine(thirdStudent.GetHashCode());
Console.WriteLine(fourthStudent.GetHashCode());
Console.WriteLine();
Student fifthStudent = (Student)firstStudent.Clone();
Console.WriteLine("-----------Cloned copy------------");
Console.WriteLine(fifthStudent); //cloned data from "firstStudent" to a new student
Console.WriteLine("Compare first student to second: {0}", firstStudent.CompareTo(secondStudent));
Console.WriteLine("Compare second student to third: {0}", secondStudent.CompareTo(thirdStudent));
Console.WriteLine("Compare third student to fourth: {0}", thirdStudent.CompareTo(fourthStudent));
Console.WriteLine();
}
示例13: Main
static void Main()
{
string decorationLine = new string('-', 80);
Console.Write(decorationLine);
Console.WriteLine("***Creating some student objects and performing some operations over them***");
Console.Write(decorationLine);
// Creating the students
Student student1 = new Student("Ivan", "Ivanov", "Ivanov", "1234567890", "Sofia, street: \"Street name\" #15", "0888888888",
"[email protected]", 2, University.SofiaUniversity, Faculty.FacultyOfLaw, Specialty.Law);
Student student2 = new Student("Petar", "Petrov", "Petrov", "0987654321", "Plovdiv, street: \"Unknown street\" #9", "0899999999",
"[email protected]", 4, University.PlovdivUniversity, Faculty.FacultyOfMathematicsAndInformatics, Specialty.Mathematics);
Console.WriteLine("***Printing the information about two students***");
// The ToString() method demonstration
Console.WriteLine(student1);
Console.WriteLine(student2);
Console.WriteLine("***Comparing the students with Equals()***");
Console.WriteLine("Result of comparison: " + student1.Equals(student2));
Console.WriteLine();
Console.WriteLine("***Testing the GetHashCode() method***");
Console.WriteLine("First student's hash code: " + student1.GetHashCode());
Console.WriteLine("Second student's has code: " + student2.GetHashCode());
Console.WriteLine();
Console.WriteLine("***Testing the operators '==' and '!='***");
Console.WriteLine("first student == second student -> " + (student1 == student2));
Console.WriteLine("first student != second student -> " + (student1 != student2));
Console.WriteLine();
Console.WriteLine("***Cloning the first student and printing the clone***");
Student cloneStudent = student1.Clone();
Console.WriteLine(cloneStudent);
Console.WriteLine("***Changing original's address and clone's mobile phone and priniting both***");
student1.Address = "Sofia, street \"New street\" #34";
cloneStudent.MobilePhone = "0877777777";
Console.WriteLine(student1);
Console.WriteLine(cloneStudent);
Console.WriteLine("***Comparing first student with second student by CompareTo() method***");
if (student1.CompareTo(student2) == 0)
{
Console.WriteLine("Both students are equal!");
}
else if (student1.CompareTo(student2) < 0)
{
Console.WriteLine("The first student is before the second one!");
}
else
{
Console.WriteLine("The first student is after the second one!");
}
}
示例14: Main
static void Main(string[] args)
{
Student student = new Student("Gosho", "Pesho", "Maria", "000-234-234", "blv. Bulgaria 5", "0876543219", "[email protected]", 4, Specialty.AncientHistory, University.SU, Faculty.Biology);
Student student2 = (Student)student.Clone();
Console.WriteLine("Student1 hashcode: {0}", student.GetHashCode());
Console.WriteLine("Student2 hashcode: {0}", student2.GetHashCode());
student.FirstName = "Pesho";
Console.WriteLine(student);
Console.WriteLine(student2);
Console.WriteLine(student.CompareTo(student2));
}
示例15: Main
static void Main()
{
Student studentOne = new Student("Mimi", "Mileva", "0901282467", Specialties.QI);
Student studentTwo = new Student("Pepi", "Ivanova", "0901282433", Specialties.QI);
Student studentThree = studentOne;
Console.WriteLine(studentOne);
Console.WriteLine("\nHash code: {0}", studentOne.GetHashCode());
Console.WriteLine("\nstudentOne Equals studentTwo: {0}", studentOne.Equals(studentTwo));
Console.WriteLine("\nstudentOne Equals studentThree: {0}", Student.Equals(studentOne, studentThree));
Console.WriteLine("\nstudentOne == studentTwo: {0}", studentOne == studentTwo);
Console.WriteLine("\nstudentOne == null: {0}", studentOne == null);
studentThree = null;
Console.WriteLine("\nstudentThree == null: {0}", studentThree == null);
Console.WriteLine("\nstudentThree != studentOne: {0}", studentThree != studentOne);
studentThree = studentOne;
Console.WriteLine("\nstudentOne != studentThree: {0}", studentOne != studentThree);
Console.WriteLine("\n\nClone studentOne in studentThree and change name and specialty in studentThree.");
studentThree = studentOne.Clone();
studentThree.FirstName = "Aneta";
studentThree.LastName = "Pesheva";
studentThree.Specialty = Specialties.Math;
Console.WriteLine("\n studentThree: {0}", studentThree);
Console.WriteLine("\n studentOne: {0}", studentOne);
Console.WriteLine("\nClone by using IColoneable.Clone()");
ICloneable clone = studentOne;
studentThree = (Student)clone.Clone();
Console.WriteLine("\n studentThree: {0}", studentThree);
Console.Write("\nCompare studentThree with studentOne result: ");
Console.WriteLine(studentThree.CompareTo(studentOne));
Console.Write("\nCompare studentOne with studentTwo result: ");
Console.WriteLine(studentOne.CompareTo(studentTwo));
Console.Write("\nCompare studentTwo with studentOne result: ");
Console.WriteLine(studentTwo.CompareTo(studentOne));
}