static void Main() { Student a = new Student("AAA", "BBB", "CCC", 322, "aaaa bbb", "12345678", "*****@*****.**", "courseAAAA", SpecialtyEnum.aaaSp, UniversityEnum.aaUn, FacultyEnum.cccFac); Student b = new Student("ZZZ", "BBB", "CCC", 321, "aaaa bbb", "12345678", "*****@*****.**", "courseAAAA", SpecialtyEnum.aaaSp, UniversityEnum.aaUn, FacultyEnum.cccFac); Student c = new Student("AAA", "BBB", "CCC", 321, "aaaa bbb", "12345678", "*****@*****.**", "courseAAAA", SpecialtyEnum.aaaSp, UniversityEnum.aaUn, FacultyEnum.cccFac); Console.WriteLine(a.ToString()); Console.WriteLine(); Console.WriteLine(b.ToString()); Console.WriteLine(); Console.WriteLine(c.ToString()); Console.WriteLine("student a is student b:{0}", a.Equals(b)); Console.WriteLine("student a is student c:{0}", a.Equals(c)); Console.WriteLine("student a is student c:{0}", a == c); Console.WriteLine("student a is not student c:{0}", a != c); Console.WriteLine("student a is not student b:{0}", a != b); Console.WriteLine("Student not overriden hash code:{0} {1} {2}", a.FirstName.GetHashCode(), a.MiddleName.GetHashCode(), a.LastName.GetHashCode()); Console.WriteLine("Student a overriden hash code:{0}", a.GetHashCode()); var d = a.Clone(); Console.WriteLine(); Console.WriteLine("Cloned student a:"); Console.WriteLine(d.ToString()); var students = new Student[] { c, b, a }.OrderBy(x => x).ToArray(); foreach (var st in students) { Console.WriteLine(st.FirstName + " " + st.MiddleName + " " + st.LastName + " " + st.SSN); } }
static void Main() { Student a = new Student("AAA", "BBB", "CCC", 322, "aaaa bbb", "12345678", "*****@*****.**", "courseAAAA", SpecialtyEnum.aaaSp, UniversityEnum.aaUn, FacultyEnum.cccFac); Student b = new Student("ZZZ", "BBB", "CCC", 321, "aaaa bbb", "12345678", "*****@*****.**", "courseAAAA", SpecialtyEnum.aaaSp, UniversityEnum.aaUn, FacultyEnum.cccFac); Student c = new Student("AAA", "BBB", "CCC", 321, "aaaa bbb", "12345678", "*****@*****.**", "courseAAAA", SpecialtyEnum.aaaSp, UniversityEnum.aaUn, FacultyEnum.cccFac); Console.WriteLine(a.ToString()); Console.WriteLine(); Console.WriteLine(b.ToString()); Console.WriteLine(); Console.WriteLine(c.ToString()); Console.WriteLine("student a is student b:{0}",a.Equals(b)); Console.WriteLine("student a is student c:{0}", a.Equals(c)); Console.WriteLine("student a is student c:{0}", a==c); Console.WriteLine("student a is not student c:{0}", a != c); Console.WriteLine("student a is not student b:{0}", a != b); Console.WriteLine("Student not overriden hash code:{0} {1} {2}",a.FirstName.GetHashCode(),a.MiddleName.GetHashCode(),a.LastName.GetHashCode()); Console.WriteLine("Student a overriden hash code:{0}",a.GetHashCode()); var d = a.Clone(); Console.WriteLine(); Console.WriteLine("Cloned student a:"); Console.WriteLine(d.ToString()); var students = new Student[] { c, b, a }.OrderBy(x => x).ToArray(); foreach (var st in students) { Console.WriteLine(st.FirstName +" " + st.MiddleName+" "+st.LastName+" "+st.SSN); } }
static void Main() { Student student1 = new Student("Ivan", "Ivanov", "Ivanov", "486939693", "Sofia", "088888888", "*****@*****.**", "first", Enums.Specialty.ComputerScience, Enums.University.TechnicalUniversity, Enums.Faculty.FacultyOfComputerSystemsAndControl); Student student2 = new Student("Ivan", "Ivanov", "Ivanov", "486939693", "Sofia", "088888888", "*****@*****.**", "first", Enums.Specialty.ComputerScience, Enums.University.TechnicalUniversity, Enums.Faculty.FacultyOfComputerSystemsAndControl); Student student3 = new Student("Ivan", "Ivanov", "Ivanov", "484830703", "Sofia", "0888999999", "*****@*****.**", "first", Enums.Specialty.ComputerScience, Enums.University.TechnicalUniversity, Enums.Faculty.FacultyOfComputerSystemsAndControl); Console.WriteLine(student1.Equals(student2)); //True Console.WriteLine(student2.Equals(student3)); //False Console.WriteLine(student1 == student2); //True Console.WriteLine(student2 != student3); //True Console.WriteLine(student1.GetHashCode()); Console.WriteLine(student2.GetHashCode()); Student newStudent = student1.Clone() as Student; student1.FirstName = "Georgi"; Console.WriteLine(student1); Console.WriteLine(); Console.WriteLine(newStudent); Console.WriteLine(student1.CompareTo(student2)); //-1 Console.WriteLine(student2.CompareTo(student3)); //1 }
private static void Main() { Student ivan = new Student { FirstName = "Ivan", MiddleName = "Ivanov", LastName = "Ivanov", Ssn = 1231231231, PermanentAddress = "Bulgaria, Sofia 1000, Minzuhar str. 123", MobilePhone = "+359887123123", Email = "*****@*****.**", Course = 2, Faculty = FacultyType.Culture, University = UniversityType.Private, Specialty = SpecialtyType.Bachelor }; Student pesho = new Student { FirstName = "Pesho", MiddleName = "Peshev", LastName = "Peshov", Ssn = 9999999999, PermanentAddress = "Bulgaria, Sofia 1000, Kokiche str. 321", MobilePhone = "+359889321321", Email = "*****@*****.**", Course = 2, Faculty = FacultyType.Economic, University = UniversityType.Public, Specialty = SpecialtyType.Doctor }; Console.WriteLine(ivan); Console.WriteLine(pesho); Console.WriteLine("Equals: {0}", pesho.Equals(ivan)); Console.WriteLine("GetHashCode() {0} {1}", "pesho", pesho.GetHashCode()); Console.WriteLine("GetHashCode() {0} {1}", "ivan", ivan.GetHashCode()); Console.WriteLine("pesho == ivan {0}", pesho == ivan); Console.WriteLine("pesho != ivan {0}", pesho != ivan); Student mircho = pesho.Clone(); mircho.FirstName = "Mircho"; mircho.MiddleName = "Mirchev"; mircho.LastName = "Mirchev"; mircho.Ssn = 9999999999; Console.WriteLine("GetHashCode() {0} {1}", "mircho", mircho.GetHashCode()); Console.WriteLine("Compare: mircho and pesho = " + mircho.CompareTo(pesho)); Console.WriteLine("Compare: mircho and mircho = " + mircho.CompareTo(mircho)); }
public static void Main(string[] args) { Student paul = new Student("Paul"); Student sally = new Student("Sally"); paul.AddGrade(3, 4.0); paul.AddGrade(4, 3.0); sally.AddGrade(3, 3.0); sally.AddGrade(3, 3.5); int paulNumberOfCredits = paul.NumberOfCredits; string paulGradeLevel = paul.GradeLevel; double paulGpa = paul.Gpa; int sallyNumberOfCredits = sally.NumberOfCredits; string sallyGradeLevel = sally.GradeLevel; double sallyGpa = sally.Gpa; paul.NumberOfCredits = 91; sally.NumberOfCredits = 61; paulGradeLevel = paul.GetGradeLevel(); sallyGradeLevel = sally.GetGradeLevel(); Console.WriteLine("Paul Number of Credits = " + paul.NumberOfCredits.ToString()); Console.WriteLine("Paul's info: "); Console.WriteLine("Gpa = " + Math.Round(paul.Gpa, 2, MidpointRounding.AwayFromZero).ToString()); Console.WriteLine("Grade Level = " + paulGradeLevel); Console.WriteLine("Sally's info: "); Console.WriteLine("Gpa = " + Math.Round(sally.Gpa, 2, MidpointRounding.AwayFromZero).ToString()); Console.WriteLine("Grade Level = " + sallyGradeLevel); // use custom ToString() method written below Console.WriteLine(paul.ToString()); Console.WriteLine(sally.ToString()); //use custom Equals and GetHashCode() methods written below Console.WriteLine("paul == sally, using customn Equals() is : " + paul.Equals(sally).ToString()); Console.WriteLine("GetHasCode() for paul is: " + paul.GetHashCode()); Console.WriteLine("GetHasCode() for sally is: " + sally.GetHashCode()); Console.ReadLine(); }
public static void Main() { Student vankata = new Student("Ivan", "Ivanov", "Ivanov", "123456789", "Grad Sofia", "0888123456", 3, UniversityEnum.UNSS, FacultyEnum.Law, SpecialtyEnum.PublicLaw); Student cloningOfVankata = (Student)vankata.Clone(); Student bugCloningOfVankata = new Student("Ivan", "Ivanov", "Ivanov", "123456798", "Grad Sofia", "0888123456", 3, UniversityEnum.UNSS, FacultyEnum.Law, SpecialtyEnum.PublicLaw); Console.WriteLine(vankata.ToString()); Console.WriteLine(vankata.GetHashCode()); Console.WriteLine(vankata.Equals(cloningOfVankata)); // return true Console.WriteLine(vankata == bugCloningOfVankata); // return false Console.WriteLine(vankata != cloningOfVankata); // return false Console.WriteLine(vankata.CompareTo(bugCloningOfVankata)); // returns -1 }
static void Main(string[] args) { Student student = new Student("Niki", "S", "Kostov", 10002922, "Telerik", "+359 882", "*****@*****.**"); student.FillUniversityInfo(Student._University.SofiaUniversity, 4, Student._Faculty.Mathematics, Student._Speciality.IT); Console.WriteLine(student.GetHashCode()); Student student2 = new Student("Ivo", "S", "Kenov", 10034222, "Telerik", "+359 883", "*****@*****.**"); student2.FillUniversityInfo(Student._University.TechnicalUniversity, 4, Student._Faculty.Mathematics, Student._Speciality.IT); Console.WriteLine(student2.GetHashCode() + Environment.NewLine); Console.WriteLine(student); Console.WriteLine(student2); Console.WriteLine(student == student2); Console.WriteLine(student.Equals(student)); Console.WriteLine(student.Equals(student2)); Console.WriteLine(student != student2); }
static void Main(string[] args) { Student a = new Student("lala", "lol", "rofl", "hladilnika", 666, 088811111, "*****@*****.**", "Hardware manufacturing", Specialty.KST, University.FreeUniversity, Faculty.Technical); Student b = new Student("lala", "lol", "rofl", "hladilnika", 666, 088811111, "*****@*****.**", "Hardware manufacturing", Specialty.KST, University.FreeUniversity, Faculty.Technical); Console.WriteLine(a.ToString()); Console.WriteLine(b.ToString()); if (a == b) { Console.WriteLine("a == b"); } if (a.Equals(b)) { Console.WriteLine("Equals "); } if (a != b) { Console.WriteLine("a and b are not equal"); } Console.WriteLine(a.GetHashCode()); Console.WriteLine(b.GetHashCode()); Student s = new Student("lala1", "lol", "rofl", "hladilnika", 666, 088811111, "*****@*****.**", "Hardware manufacturing", Specialty.KST, University.FreeUniversity, Faculty.Technical); Console.WriteLine(s.GetHashCode()); if (a != s) { Console.WriteLine("a and c are not equal"); } }
public static void Main() { var firstStudent = new Student("Kiro", "Skalata", "Valchev", "123-45-6789", "Unknown address", "0888747474", "*****@*****.**", 4, Universities.MedicalUniversity, Faculties.DentalMedicineFaculty, Specialties.DentalMedicine); var secondStudent = new Student("Kiro", "Skalata", "Valchev", "987-65-4321", "Unknown address", "0886454545", "*****@*****.**", 4, Universities.SofiaUniversity, Faculties.FMI, Specialties.SoftwareEngineer); var thirdStudent = new Student("Dimitar", "Pishtova", "Marinov", "321-56-9784", "Unknown address", "0895636363", "*****@*****.**", 4, Universities.TechnicalUniversity, Faculties.TransportFaculty, Specialties.TransportEngineer); bool compareFirstAndSecond = firstStudent.Equals(secondStudent); bool compareFirstAndThird = firstStudent.Equals(thirdStudent); bool operatorsCompareFirstAndSecond = firstStudent == secondStudent; bool operatorsCompareFirstAndThird = firstStudent != thirdStudent; var hashCodeTest = firstStudent.GetHashCode(); // test ToString(); Console.WriteLine(firstStudent + "\n"); Console.WriteLine(secondStudent + "\n"); Console.WriteLine(thirdStudent + "\n"); Console.WriteLine("Compare first and second with Equals: {0}", compareFirstAndSecond); Console.WriteLine("Compare first and third with Equals: {0}\n", compareFirstAndThird); Console.WriteLine("Compare first and second with == {0}", operatorsCompareFirstAndSecond); Console.WriteLine("Compare first and third with == {0}\n", operatorsCompareFirstAndThird); Console.WriteLine("Compare first and second with CompareTo: {0}", firstStudent.CompareTo(secondStudent)); Console.WriteLine("Compare first and third with CompareTo: {0}\n", firstStudent.CompareTo(thirdStudent)); var cloned = thirdStudent.Clone() as Student; Console.WriteLine("Cloned == thirdStudent? {0}", cloned == thirdStudent); thirdStudent = secondStudent; Console.WriteLine("Cloned == thirdStudent? after swapping? {0}", cloned == thirdStudent); }
public static void Main() { var student = new Student("Pesho", "Petrov", "Peshov", "123-45-6789", "some address", "some phone", "some eMail", 2, Universities.TU, Faculties.Mathematics, Specialities.Drinking); var otherStudent = new Student("Pesho", "Petrov", "Peshov", "000-11-2222", "some address", "some phone", "some eMail", 2, Universities.TU, Faculties.Mathematics, Specialities.Drinking); Console.WriteLine(" Two students with same names, universities and all, except SSN:"); Console.WriteLine("{0}\n -{1}'s hash code = {2}\n", student, student.FirstName, student.GetHashCode()); Console.WriteLine("{0}\n -{1}'s hash code = {2}\n", otherStudent, otherStudent.FirstName, otherStudent.GetHashCode()); Console.WriteLine("Are the two students equal? - {0}", student == otherStudent); Console.WriteLine("Are the two students different? - {0}", student != otherStudent); Console.Write(separator); Console.WriteLine(" Two students, one is clone of the other:"); var clone = (Student)student.Clone(); clone.Course = 4; clone.MobilePhone = "another phone"; clone.PermanentAddress = "new address"; Console.WriteLine("Original: {0}", student); Console.WriteLine("Clone with changed phone, address and course: {0}", clone); Console.WriteLine("The original is not affected by changes made in the clone."); Console.Write(separator); Student newStudent = new Student("Gosho", "Petrov", "Peshov", "123-45-6789", "some address", "some phone", "some eMail", 2, Universities.TU, Faculties.Mathematics, Specialities.Dancing); Console.WriteLine(" Comparing two students with same names but different SSNs: "); CompareStudents(student, otherStudent); Console.WriteLine(" Comparing two students with different names: "); CompareStudents(student, newStudent); Console.WriteLine(" Comparing two students with same names and SSNs: "); CompareStudents(student, clone); Console.Write(separator); }