static void Main(string[] args) { Student st = new Student("Ivan", "Ivanov", "Ivanov", "123456789", "Mladost 4, Sofia, Bulgaria", "0888888888", "*****@*****.**", 2, Specialty.Botany, Faculty.Biology, University.Oxford); Console.WriteLine(st.Email); Console.WriteLine(st.ToString()); Console.WriteLine(); Student st2 = st; Student st3 = new Student("Petar", "Petrov", "Petrov", "123321312", "Lyulin 18, Sofia, Bulgaria", "0999999999", "*****@*****.**", 2, Specialty.Botany, Faculty.Biology, University.Oxford); Console.WriteLine("Equals: {0}", st3.Equals(st)); Console.WriteLine("== operator: {0}", st == st2); Console.WriteLine("HashCode: {0}", st.GetHashCode()); Console.WriteLine(); Console.WriteLine("Clone:"); var st8 = st3.Clone(); Console.WriteLine(st8.ToString()); Console.WriteLine("Clone equals: {0}", st3.Equals(st8)); Console.WriteLine("Clone == operator: {0}", st3 == st8); Console.WriteLine(); Console.WriteLine(st.CompareTo(st3)); Console.WriteLine(); }
private static void Main() { var pesho1 = new Student("Pesho", "Petrov", "Petrov", "999999999", "Kaspichan 2", "088889788", "*****@*****.**", 3, SpecialitiesEnum.Economics, UniversitiesEnum.Unss, FacultiesEnum.StatisticsAndInformatics); var pesho2 = new Student("Pesho", "Petrov", "Petrov", "999999999", "Kaspichan 2", "088889788", "*****@*****.**", 3, SpecialitiesEnum.Economics, UniversitiesEnum.Unss, FacultiesEnum.StatisticsAndInformatics); var gosho = new Student("Gosho", "Georgiev", "Georgiev", "888888888", "Kaspichan 1", "089889788", "*****@*****.**", 3, SpecialitiesEnum.Biology, UniversitiesEnum.Su, FacultiesEnum.AppliedScience); Console.WriteLine("We have three students: "); Console.WriteLine(pesho1); Divide(); Console.WriteLine(pesho2); Divide(); Console.WriteLine(gosho); Divide(); Console.ForegroundColor = ConsoleColor.Green; var areTheyEqual = pesho1.Equals(pesho2); Console.WriteLine("The Pesho and Pesho are equal: " + areTheyEqual + " => when we use CompareTo we get: " + pesho2.CompareTo(pesho1)); areTheyEqual = pesho1.Equals(gosho); Console.WriteLine("The Pesho and Gosho are equal: " + areTheyEqual + " => when we use CompareTo we get: " + gosho.CompareTo(pesho1)); areTheyEqual = pesho1 == pesho2; Console.WriteLine("The Pesho and Pesho are equal with equality operator: " + areTheyEqual); areTheyEqual = pesho1 == gosho; Console.WriteLine("The Pesho and Gosho are equal with equality operator: " + areTheyEqual); Console.WriteLine("Pesho hash code:" + pesho1.GetHashCode()); Console.WriteLine("Second Pesho hash code: " + pesho2.GetHashCode()); Console.WriteLine("Gosho hash code: " + gosho.GetHashCode()); Divide(); Console.WriteLine("Lets copy Gosho and change his info."); var ivan = (Student)gosho.Clone(); ivan.FirstName = "Ivan"; ivan.LastName = "Vladimirov"; ivan.Ssn = "777777777"; ivan.Email = "*****@*****.**"; ivan.Address = "Parvomai"; ivan.Speciality = SpecialitiesEnum.BusinessAdministration; ivan.Faculty = FacultiesEnum.StatisticsAndInformatics; Divide(); Console.WriteLine(ivan); Divide(); Console.WriteLine("Gosho is still the same."); Console.WriteLine(gosho); Console.ForegroundColor = ConsoleColor.Gray; }
public static void Main() { Student firstStudent = new Student("Ivan", "Vasilev", "Georgiev", "234-23-4567", "Address", "0888345678", "*****@*****.**", 1, Specialty.Biology, University.PlovdivUniversity, Faculty.BiologyFaculty); Console.WriteLine("First student:\n\n" + firstStudent); Console.WriteLine("First student hash code: {0}\n", firstStudent.GetHashCode()); Student secondStudent = firstStudent; Console.WriteLine("Second student:\n\n" + secondStudent); Console.WriteLine("DoesReferenceEquals(firstStudent, secondStudent)? : {0}\n", ReferenceEquals(firstStudent, secondStudent)); Student thirdStudent = (Student)secondStudent.Clone(); Console.WriteLine("Third student (cloned second student):\n\n" + thirdStudent); Console.WriteLine("DoesReferenceEquals(thirdStudent, secondStudent)? : {0}\n", ReferenceEquals(thirdStudent, secondStudent)); secondStudent = new Student("Peter", "Pavlov", "Petrov", "888-23-4567", "Address", "0888345888", "*****@*****.**", 2, Specialty.Chemistry, University.SofiaUniversity, Faculty.ChemistryFaculty); Console.WriteLine("Second student (changed):\n\n" + secondStudent); Console.WriteLine("Third student:\n\n" + thirdStudent); Console.WriteLine("firstStudent != secondStudent : {0}", firstStudent != secondStudent); Console.WriteLine("firstStudent.Equals(secondStudent)) : {0}", firstStudent.Equals(secondStudent)); Console.WriteLine("firstStudent.CompareTo(secondStudent) : {0}\n", firstStudent.CompareTo(secondStudent)); }
private static void Main() { var test = new Student("Pesho", "Petrov", "Petrov", 192, "tri", "+359887005", "*****@*****.**", "Math", "Algorythms", "TU", "FMI"); var test2 = new Student("Pesho", "Petrov", "Petrov", 193, "tri", "+359887005", "*****@*****.**", "Math", "Algorythms", "SU", "FMI"); Console.WriteLine(test.GetHashCode()); Console.WriteLine(test2.GetHashCode()); Console.WriteLine(test.Equals(test2)); Console.WriteLine(test); Console.WriteLine(test2); var clone = test.Clone(); Console.WriteLine(clone); Console.WriteLine(test.Equals(clone)); Console.WriteLine(test == clone); Console.WriteLine(test == clone as Student); Console.WriteLine(test.CompareTo(test2)); }
static void Main() { Student Pesho = new Student("Pesho", "Petrov", "Petrov", 12546, "Sofia", "+356 558 566 552", "*****@*****.**"); Pesho.UniversityInf(Student.EnumUniversity.SofiaUniversity, 3, Student.EnumFaculty.MatematicaAndInformatica, Student.EnumSpeciality.MatematicaAndInformatica); Console.WriteLine(Pesho.GetHashCode()); Student Gosho = new Student("Georgi", "Georgiev", "Stanchev", 536312, "Varna", "+245 526 665 523", "*****@*****.**"); Gosho.UniversityInf(Student.EnumUniversity.VTU, 4, Student.EnumFaculty.Medicine, Student.EnumSpeciality.Dentist); Console.WriteLine(Gosho.GetHashCode()); Console.WriteLine(Pesho); Console.WriteLine(Gosho); Console.WriteLine(Pesho==Gosho); Console.WriteLine(Pesho.Equals(Pesho)); Console.WriteLine(Pesho.Equals(Gosho)); Console.WriteLine(Pesho!=Gosho); }
public static void Main() { Student firstStudent = new Student("Stamat", "Stamatov", "Stamatev", "1112131415", "StudentskiCity", "0888112233", "*****@*****.**", 1, Specialty.Literature, University.SofiaUniversity, Faculty.Literature); Console.WriteLine("First student:\n\n" + firstStudent); Console.WriteLine("First student hash code: {0}\n", firstStudent.GetHashCode()); Student secondStudent = firstStudent; Console.WriteLine("Second student:\n\n" + secondStudent); Console.WriteLine("DoesReferenceEquals(firstStudent, secondStudent)? : {0}\n", ReferenceEquals(firstStudent, secondStudent)); Student thirdStudent = (Student)secondStudent.Clone(); Console.WriteLine("Third student (cloned second student):\n\n" + thirdStudent); Console.WriteLine("DoesReferenceEquals(thirdStudent, secondStudent)? : {0}\n", ReferenceEquals(thirdStudent, secondStudent)); secondStudent = new Student("Oh", "Kotio", "Kotev", "12455623125", "Address", "0888765432", "*****@*****.**", 2, Specialty.Chemistry, University.SofiaUniversity, Faculty.Physics); Console.WriteLine("Second student (changed):\n\n" + secondStudent); Console.WriteLine("Third student:\n\n" + thirdStudent); Console.WriteLine("firstStudent != secondStudent : {0}", firstStudent != secondStudent); Console.WriteLine("firstStudent.Equals(secondStudent)) : {0}", firstStudent.Equals(secondStudent)); Console.WriteLine("firstStudent.CompareTo(secondStudent) : {0}\n", firstStudent.CompareTo(secondStudent)); }
private static void TestStudentClass() { var sb = new StringBuilder(); var peshoStudent = new Student("Pesho", "Peshov", 4, 222, Specialty.QA, University.TilirikUniversity, Faculty.SoftwareFaculty); var goshoStudent = new Student("Gosho", "Goshov", 2, 123, Specialty.MobileDevelopment, University.TilirikUniversity, Faculty.SoftwareFaculty); var oneMorePeshoStudent = new Student("Pesho", "Goshov", 2, 456, Specialty.MobileDevelopment, University.TilirikUniversity, Faculty.SoftwareFaculty); var anotherPeshoStudent = peshoStudent.Clone(); sb.AppendLine(peshoStudent.ToString()) .AppendLine(goshoStudent.ToString()) .AppendLine("Pesho equals Gosho?") .AppendFormat("Equals: {0}", peshoStudent.Equals(goshoStudent)) .AppendLine() .AppendFormat("==: {0}", peshoStudent == goshoStudent) .AppendLine() .AppendFormat("!=: {0}", peshoStudent != goshoStudent) .AppendLine() .AppendLine("\nPesho cloned: ") .AppendLine(anotherPeshoStudent.ToString()) .AppendLine("Compare Pesho & Gosho: " + peshoStudent.CompareTo(goshoStudent).ToString()) .AppendLine("Compare Pesho & one more Pesho student: " + peshoStudent.CompareTo(oneMorePeshoStudent).ToString()) .AppendLine("Compare Pesho & Pesho copy: " + peshoStudent.CompareTo(anotherPeshoStudent).ToString()); Console.WriteLine(sb); }
static void Main() { Student Pesho = new Student("Pesho", "Petrov", "Petrov", 12546, "Sofia", "+356 558 566 552", "*****@*****.**"); Pesho.UniversityInf(Student.EnumUniversity.SofiaUniversity, 3, Student.EnumFaculty.MatematicaAndInformatica, Student.EnumSpeciality.MatematicaAndInformatica); Console.WriteLine(Pesho.GetHashCode()); Student Gosho = new Student("Georgi", "Georgiev", "Stanchev", 536312, "Varna", "+245 526 665 523", "*****@*****.**"); Gosho.UniversityInf(Student.EnumUniversity.VTU, 4, Student.EnumFaculty.Medicine, Student.EnumSpeciality.Dentist); Console.WriteLine(Gosho.GetHashCode()); Console.WriteLine(Pesho); Console.WriteLine(Gosho); Console.WriteLine(Pesho == Gosho); Console.WriteLine(Pesho.Equals(Pesho)); Console.WriteLine(Pesho.Equals(Gosho)); Console.WriteLine(Pesho != Gosho); }
static void Main(string[] args) { Student student = new Student("Jhon", "M", "Jakson", 10002922, "Telerik", "+359 885", "*****@*****.**"); student.FillUniversityInfo(Student._University.SofiaUniversity, 4, Student._Faculty.Mathematics, Student._Speciality.IT); Console.WriteLine(student.GetHashCode()); Student student2 = new Student("Mark", "S", "Morison", 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); }
private static void Main() { var test = new Student("Pesho", "Petrov", "Petrov", 192, "tri", "+359887005", "*****@*****.**", "Math", "Algorythms", "TU", "FMI"); var test2 = new Student("Pesho", "Petrov", "Petrov", 193, "tri", "+359887005", "*****@*****.**", "Math", "Algorythms", "SU", "FMI"); Console.WriteLine(test.GetHashCode()); Console.WriteLine(test2.GetHashCode()); Console.WriteLine(test.Equals(test2)); Console.WriteLine(test); Console.WriteLine(test2); var clone = test.Clone(); Console.WriteLine(clone); Console.WriteLine(test.Equals(clone)); Console.WriteLine(test == clone); Console.WriteLine(test == clone as Student); Console.WriteLine(test.CompareTo(test2)); }
static void Main() { Student student1 = new Student ("Anton", "Dimitrov", "Ivanov", 1497845, "Ul. Briast 13", "099922233", "*****@*****.**", 2, Speciality.Statistic, University.TU, Faculty.Mathemathical); Student student2 = new Student("Anton", "Dimitrov", "Ivanov", 1497845, "Ul. Briast 13", "099922233", "*****@*****.**", 2, Speciality.Statistic, University.TU, Faculty.Mathemathical); Console.WriteLine("Student1.Equals(Student2) - {0}", student1.Equals(student2)); student2.FirstName = "Ivan"; Console.WriteLine("After changes in student 2 - Student1.Equals(Student2) - {0}", student1.Equals(student2)); Console.WriteLine("student1 == student2 - {0}", student1 == student2); Console.WriteLine("student1 != student2 - {0}", student1 != student2); Console.WriteLine("Student1 hask code - {0}", student1.GetHashCode()); Console.WriteLine(); Console.WriteLine("02.IClonable"); Console.WriteLine(new string('-', Console.WindowWidth)); var clone = student1.Clone() as Student; Console.WriteLine("Clone of student1"); Console.WriteLine(clone); Console.WriteLine(); student1.FirstName = "Darin"; student1.Course = 3; student1.Speciality = Speciality.FinancialManagment; Console.WriteLine("Student1 after some changes"); Console.WriteLine(student1); Console.WriteLine(); Console.WriteLine("Cloned student has not changed"); Console.WriteLine(clone); Console.WriteLine(); Console.WriteLine(); Console.WriteLine("03.IComparable"); Console.WriteLine(new string('-', Console.WindowWidth)); if(student1.CompareTo(student2) > 0) { Console.WriteLine("student1 < student2"); } else if(student1.CompareTo(student2) < 0) { Console.WriteLine("student1 > student2"); } else { Console.WriteLine("student1 = student2"); } }
static void Main(string[] args) { var gosho = new Student("Gosho", "Goshov", "Goshov", 9536478, "Daleko", "646854654", 2, Specialty.Geodesy, Universities.UACEG, Faculties.second); var pesho = new Student("Pesho", "Peshov", "Peshov", 89465468, "Blizo", "658874688", 3, Specialty.Informatics, Universities.TU, Faculties.first); Console.WriteLine(gosho.Equals(pesho)); }
static void Main(string[] args) { Student student = new Student( "Miro", "Peshev", "Goshov", "5524887456", "blv Vitosha 243", "0896565689", "*****@*****.**", "Math and Stuff", Speciality.Math, University.IIT, Faculty.Math); Console.WriteLine("to string:" + student.ToString()); var otherStudent = student.Clone(); Console.WriteLine("Cloned student to string: " + otherStudent.ToString()); Console.WriteLine(student == otherStudent); Console.WriteLine(student.Equals(student)); Console.WriteLine(student.Equals(otherStudent)); Console.WriteLine(student != otherStudent); }
static void Main() { List <Student> students = new List <Student>(); students.Add(new Student("Ivan", "Karlito", "Ivanov", 123212434, "ul.Makedonska", 0885433154, "*****@*****.**", 2, enumSpecialities.Mehatronics, enumUniversities.UNWE, enumFaculties.MechanicalFaculty)); students.Add(new Student("Chicho", "Iliq", "Petkov", 873206934, "ul.Strandja", 0865433524, "*****@*****.**", 4, enumSpecialities.SSS, enumUniversities.UASG, enumFaculties.SSSFaculty)); foreach (var student in students) { Console.WriteLine(student); } Console.WriteLine("Comparing students direct with the overriden method Equals."); var comparingStudentsEquals = Equals(students[0], students[1]); Console.WriteLine("{0}\n", comparingStudentsEquals); Console.WriteLine("Comparing students direct with the == operator method."); var comparingWithFirstOperator = Student.Equals(students[0], students[1]); Console.WriteLine("{0}\n", comparingWithFirstOperator); Console.WriteLine("Comparing students direct with the != operator method."); var comparingWithSecondOperator = !Student.Equals(students[0], students[1]); Console.WriteLine("{0}\n", comparingWithSecondOperator); Console.WriteLine("Using GetHashCode method."); var getHashCodeFirst = students[0].GetHashCode(); var getHashCodeSecond = students[1].GetHashCode(); Console.WriteLine("HashCode for first student {0}", getHashCodeFirst); Console.WriteLine("HashCode for second student {0}\n", getHashCodeSecond); Console.WriteLine("Cloning a student."); //task2 var clonedStudent = students[0].Clone(); Console.WriteLine(clonedStudent); Console.WriteLine("IComparable:"); //task3 var comparingStudents = students[0].CompareTo(students[1]); if (comparingStudents < 0) { Console.WriteLine("Students are with different names: {0} and {1}", students[0].FirstName, students[1].FirstName); } else { Console.WriteLine("Students are with same names: {0} and {1}", students[0].FirstName, students[1].FirstName); } }
private static void TestStudent() { var stud = new Student("Pesho", "Ivanov", "Georgiev", "999-00-4444", "Pesho`s address is deep secret", "+1 155 1254845", "*****@*****.**", "Programming", Specialties.Engineering, Faculties.Programming, University.MIT); var evilTwin = (Student)stud.Clone(); Console.WriteLine("GetHashCode() return: {0}", stud.GetHashCode() == evilTwin.GetHashCode()); Console.WriteLine("Equals return: {0}", stud.Equals(evilTwin)); Console.WriteLine("CompareTo return: {0}", stud.CompareTo(evilTwin)); }
static void Main(string[] args) { Student student = new Student( "Miro", "Peshev", "Goshov", "5524887456", "blv Vitosha 243", "0896565689", "*****@*****.**", "Math and Stuff", Speciality.Math, University.IIT, Faculty.Math); Console.WriteLine("to string:" + student.ToString()); var otherStudent = student.Clone(); Console.WriteLine("Cloned student to string: " + otherStudent.ToString()); Console.WriteLine(student == otherStudent); Console.WriteLine(student.Equals(student)); Console.WriteLine(student.Equals(otherStudent)); Console.WriteLine(student != otherStudent); }
public static void Main() { Student st = new Student("Black", University.UASG); var st1 = new Student("John", "Smith",11234,"World","09841233","*****@*****.**", 4, University.SofiaUniversity, Specialty.SoftwareDevelopment,Faculty.Informatics); Console.WriteLine(st.Equals(st1)); Console.WriteLine(st1.ToString()); if (st1 == st) { Console.WriteLine("Equal"); } else { Console.WriteLine("False"); } }
static void Main() { Student student1 = new Student("Anton", "Dimitrov", "Ivanov", 1497845, "Ul. Briast 13", "099922233", "*****@*****.**", 2, Speciality.Statistic, University.TU, Faculty.Mathemathical); Student student2 = new Student("Anton", "Dimitrov", "Ivanov", 1497845, "Ul. Briast 13", "099922233", "*****@*****.**", 2, Speciality.Statistic, University.TU, Faculty.Mathemathical); Console.WriteLine("Student1.Equals(Student2) - {0}", student1.Equals(student2)); student2.FirstName = "Ivan"; Console.WriteLine("After changes in student 2 - Student1.Equals(Student2) - {0}", student1.Equals(student2)); Console.WriteLine("student1 == student2 - {0}", student1 == student2); Console.WriteLine("student1 != student2 - {0}", student1 != student2); Console.WriteLine("Student1 hask code - {0}", student1.GetHashCode()); Console.WriteLine(); Console.WriteLine("02.IClonable"); Console.WriteLine(new string('-', Console.WindowWidth)); var clone = student1.Clone() as Student; Console.WriteLine("Clone of student1"); Console.WriteLine(clone); Console.WriteLine(); student1.FirstName = "Darin"; student1.Course = 3; student1.Speciality = Speciality.FinancialManagment; Console.WriteLine("Student1 after some changes"); Console.WriteLine(student1); Console.WriteLine(); Console.WriteLine("Cloned student has not changed"); Console.WriteLine(clone); Console.WriteLine(); Console.WriteLine(); Console.WriteLine("03.IComparable"); Console.WriteLine(new string('-', Console.WindowWidth)); if (student1.CompareTo(student2) > 0) { Console.WriteLine("student1 < student2"); } else if (student1.CompareTo(student2) < 0) { Console.WriteLine("student1 > student2"); } else { Console.WriteLine("student1 = student2"); } }
public static void Main() { var peshoStudent = new Student("Pesho", "Stamatov", "Peshev", 1234, "Address", "0899635423", "*****@*****.**", 2, University.MU, Faculties.Dental, Specialities.Medicine); var joroStudent = new Student("Joro", "Georgiev", "Peshev", 2234, "Address", "0899635423", "*****@*****.**", 4, University.TU, Faculties.Telecomunications, Specialities.Tellecomunications); Console.WriteLine(peshoStudent.ToString()); // Task 1 Console.WriteLine("HashCode: {0}", peshoStudent.GetHashCode()); // Task 1 Console.WriteLine(peshoStudent.Equals(joroStudent)); // Task 1 Console.WriteLine(peshoStudent == joroStudent); Console.WriteLine(peshoStudent != joroStudent); var cloneStudent = peshoStudent.Clone(); // Task 2 Console.WriteLine(new string('-', 50)); Console.WriteLine(cloneStudent.ToString()); Console.WriteLine(peshoStudent.CompareTo(joroStudent)); // Task 3 }
static void Main() { Student firstStudent = new Student("Ivan", "Ivanov", "Ivanov", "8912123434", "bul. Bulgaria 1", "0888888888", "*****@*****.**", 4, Specialty.CST, Faculty.FKSU, University.TUSofiya); Student secondStudent = new Student("Stefaniya", "Stefanova", "Stefanova", "9011115757", "bul. Al.Malinov 1", "0888555555", "*****@*****.**", 3, Specialty.EngineerDesign, Faculty.MF, University.TUSofiya); Student thirdStudent = new Student("Stefaniya", "Stefanova", "Stefanova", "9011115757", "bul. Al.Malinov 1", "0888555555", "*****@*****.**", 3, Specialty.EngineerDesign, Faculty.MF, University.TUSofiya); // Testing the ToString() method Console.WriteLine("Testing the ToString() method:"); Console.WriteLine(new string('-', 30)); Console.WriteLine(firstStudent); Console.WriteLine(secondStudent); // Testing the GetHashCode() and Equals methods Console.WriteLine("Testing the GetHashCode() and Equals() methods:"); Console.WriteLine(new string('-', 47)); Console.WriteLine("Result of the Equals() method for the third and the second student: {0}", thirdStudent.Equals(secondStudent)); Console.WriteLine("First student HashCode: " + firstStudent.GetHashCode()); Console.WriteLine("Second student HashCode: " + secondStudent.GetHashCode()); Console.WriteLine("Result of the Equals() method for the hashcodes of the first and the second student: " + firstStudent.GetHashCode().Equals(secondStudent.GetHashCode())); Console.WriteLine("Result of the Equals() method for the hashcodes of the third and the second student: " + thirdStudent.GetHashCode().Equals(secondStudent.GetHashCode())); Console.WriteLine(); // Testing the == and != operators Console.WriteLine("Testing the == and != operators:"); Console.WriteLine(new string('-', 32)); Console.WriteLine("First student == Second student: {0}", firstStudent == secondStudent); Console.WriteLine("Second student == Third student: {0}", secondStudent == thirdStudent); Console.WriteLine("First student != Second student: {0}", firstStudent != secondStudent); Console.WriteLine("Second student != Third student: {0}", secondStudent != thirdStudent); Console.WriteLine(); // Testing the Clone() method Console.WriteLine("Testing the Clone() method:"); Console.WriteLine(new string('-', 27)); Student copiedStudent = firstStudent.Clone() as Student; Console.WriteLine("First student clone == First student: {0}", copiedStudent == firstStudent); Console.WriteLine(); // Testing the CompareTo() method Console.WriteLine("Testing the CompareTo() method:"); Console.WriteLine(new string('-', 31)); Console.WriteLine("First student compared to the second student: {0}", firstStudent.CompareTo(secondStudent)); Console.WriteLine("Second student compared to the first student: {0}", secondStudent.CompareTo(firstStudent)); Console.WriteLine("Cloned student compared to the first student: {0}", copiedStudent.CompareTo(firstStudent)); }
public static void Main() { var student = new Student("Ivan", "Ivanov", "Draganov", "353406", "Sofia", "0888256859", "*****@*****.**", 3, University.TUGabrovo, Specialty.AIUT, Faculty.FEA); var otherStudent = new Student("Ivan", "Peshov", "Peshovski", "352789", "Plovdiv", "+359857457412", "*****@*****.**", 3, University.TUSofia, Specialty.AIUT, Faculty.FEA); var anotherStudent = new Student("Asen", "Atanasov", "Petkov", "345879", "Burgas", "0889789888", "*****@*****.**", 2, University.TUGabrovo, Specialty.CST, Faculty.FEA); //Equals() Console.WriteLine(student.Equals(otherStudent)); //ToString() Console.WriteLine(student); //GetHashCode() Console.WriteLine(student.GetHashCode()); Console.WriteLine(otherStudent.GetHashCode()); //== and != Console.WriteLine(student == otherStudent); Console.WriteLine(student != otherStudent); //Problem 2 var clonedStudent = (Student)student.Clone(); Console.WriteLine("\nProblem 2"); Console.WriteLine(clonedStudent); //Problem 3 var students = new SortedSet <Student>(); students.Add(student); students.Add(otherStudent); students.Add(anotherStudent); Console.WriteLine("\nProblem 3"); foreach (var st in students) { Console.WriteLine(st); } }
public static void Main() { // initaialise two students - the ususal suspects - Pesho and Gosho Student pesho = new Student("Pesho", "Peshev", "Peshev", "2036984", "15 Peshova dolina str., Peshov Dol", "+35988800800", "*****@*****.**", "Nekaf kurs", Specialty.SomeSPecialityOne, University.SomeUniversityOne, Faculty.SomeFacultyOne); Student gosho = new Student("Gosho", "Goshev", "Goshev", "3058520", "10 Goshova livada str, Gohotown", "+35989900900", "*****@*****.**", "Drug kurs", Specialty.SomeSpecialityTwo, University.SomeUniversityTwo, Faculty.SOmeFacultyTwo); // Print them to consol to check override of ToString() method Console.WriteLine("Pesho"); Console.WriteLine(pesho); Console.WriteLine("\nGosho"); Console.WriteLine(gosho); // Make a deep copy of Gosho Student clonedGosho = (Student)gosho.Clone(); Console.WriteLine("\nCloned gosho:"); Console.WriteLine(clonedGosho); // Change the first name og Cloned Gosho and print it and the original one clonedGosho.FirstName = "Izomrud"; Console.WriteLine("\nCloned gosho with changed first name:"); Console.WriteLine(clonedGosho); Console.WriteLine("\nGosho again to check if the clone is deep:"); Console.WriteLine(gosho); // chesk the overridin of Equal() Console.WriteLine("\nCheck Equal gosho ang pesho"); Console.WriteLine(pesho.Equals(gosho)); // Print hash codes Console.WriteLine("\nPrint hach codes of gosho and pesho:"); Console.WriteLine(pesho.GetHashCode()); Console.WriteLine(gosho.GetHashCode()); Console.WriteLine(clonedGosho.GetHashCode()); // Compare Gosho to Pesho Console.WriteLine("\nPrint result of compare gosho to pesho: "); Console.WriteLine(gosho.CompareTo(pesho)); }
public static void Main() { var student = new Student("Ivan", "Ivanov", "Draganov", "353406", "Sofia", "0888256859", "*****@*****.**", 3, University.TUGabrovo, Specialty.AIUT, Faculty.FEA); var otherStudent = new Student("Ivan", "Peshov", "Peshovski", "352789", "Plovdiv", "+359857457412", "*****@*****.**", 3, University.TUSofia, Specialty.AIUT, Faculty.FEA); var anotherStudent = new Student("Asen", "Atanasov", "Petkov", "345879", "Burgas", "0889789888", "*****@*****.**", 2, University.TUGabrovo, Specialty.CST, Faculty.FEA); //Equals() Console.WriteLine(student.Equals(otherStudent)); //ToString() Console.WriteLine(student); //GetHashCode() Console.WriteLine(student.GetHashCode()); Console.WriteLine(otherStudent.GetHashCode()); //== and != Console.WriteLine(student == otherStudent); Console.WriteLine(student != otherStudent); //Problem 2 var clonedStudent = (Student)student.Clone(); Console.WriteLine("\nProblem 2"); Console.WriteLine(clonedStudent); //Problem 3 var students = new SortedSet<Student>(); students.Add(student); students.Add(otherStudent); students.Add(anotherStudent); Console.WriteLine("\nProblem 3"); foreach (var st in students) { Console.WriteLine(st); } }
static void Main() { Student firstStudent = new Student("Ivan", "Petrov", "Ivanov", 456789, "Burgas, ul. Ferdinandova", "088456789", "*****@*****.**", 3, Specialty.InformationTechnology, University.TechnicalUniversity, Faculty.InformationFac); Student secondStudent = new Student("Petar", "Petrov", "Ivanov", 123456, "Burgas, ul. Carigradska", "082342356", "*****@*****.**", 4, Specialty.Mathematics, University.SofiaUniversity, Faculty.MathematicsFac); Student thirdStudent = new Student("Wania", "Petrova", "Dimova", 359456, "Burgas, ul. Hristo Botev", "082342356", "*****@*****.**", 1, Specialty.SoftwareEngineering, University.TechnicalUniversity, Faculty.SoftwareFac); Console.WriteLine("-------------------------------------"); Console.WriteLine(firstStudent.ToString()); Console.WriteLine("-------------------------------------"); Console.WriteLine(secondStudent.ToString()); Console.WriteLine("-------------------------------------"); Console.WriteLine(thirdStudent.ToString()); Console.WriteLine("-------------------------------------"); Console.WriteLine(firstStudent == secondStudent); Console.WriteLine(firstStudent != thirdStudent); Console.WriteLine(firstStudent.Equals(secondStudent)); Console.WriteLine(thirdStudent.Equals(thirdStudent)); Student firstStudentCopy = firstStudent.Clone(); Console.WriteLine("-------------------------------------"); Console.WriteLine(firstStudentCopy); firstStudentCopy.Specialty = Specialty.SoftwareEngineering; firstStudentCopy.University = University.TechnicalUniversity; firstStudentCopy.Faculty = Faculty.SoftwareFac; Console.WriteLine("-------------------------------------"); Console.WriteLine(firstStudent); Console.WriteLine("-------------------------------------"); Console.WriteLine(firstStudentCopy); }
public static void Main() { Student pesho = new Student("pesho","pehov","goshov",555,"Ul Marica","53646546","*****@*****.**",4,UniversityEnum.TechnicalUniversity,FacultyEnum.Mathematics,SpecialtyEnum.IT); Student secondPesho = new Student("pesho", "pehov", "goshov", 555, "Ul Marica", "53646546", "*****@*****.**", 4, UniversityEnum.TechnicalUniversity, FacultyEnum.Mathematics, SpecialtyEnum.IT); Student gosho = new Student("gosho", "pehov", "goshov", 5453555, "Ul Rarica", "53644456546", "*****@*****.**", 4, UniversityEnum.TechnicalUniversity, FacultyEnum.Mathematics, SpecialtyEnum.IT); Console.WriteLine(pesho.ToString()); if (pesho==secondPesho) { Console.WriteLine("Operator == works fine!"); } if (pesho!=secondPesho) { Console.WriteLine("Doesn't work"); } else { Console.WriteLine("Operator != works fine!"); } Console.WriteLine(); Console.Write("Equals method: "); Console.WriteLine(pesho.Equals(secondPesho)); Console.WriteLine(); Console.Write("Pesho get hash code method: "); Console.WriteLine(pesho.GetHashCode()); Console.Write("Gosho get hash code method: "); Console.WriteLine(gosho.GetHashCode()); Console.WriteLine(); Console.WriteLine("Copy of pesho:"); Student peshoCopy = pesho.Clone() as Student; Console.WriteLine(peshoCopy); Console.Write("Pesho compare to copy of pesho: "); Console.WriteLine(pesho.CompareTo(peshoCopy)); }
public static bool operator !=(Student firstStudent, Student secondStudent) { return(!Student.Equals(firstStudent, secondStudent)); }
public static void Main(string[] args) { Person pesho = new Person("Peter"); Console.WriteLine(pesho); var mincho = new Student( "Mincho", "Hristov", "Petrov", 323453, "Sofia", 0888888888, "*****@*****.**", 2, Specialty.Engines, University.TUSofia, Faculty.ComputerScience); var penka = new Student( "Penka", "Slavova", "Litova", 323453, "Varna", 0888123456, "*****@*****.**", 2, Specialty.PlasticSurgery, University.MedicalUniversity, Faculty.Chemistry); Student pencho = new Student( "Mincho", "Hristov", "Petrov", 323453, "Sofia", 0888765488, "*****@*****.**", 5, Specialty.HumanBehavior, University.UniSofia, Faculty.Psychology); Console.WriteLine("Mincho equals pencho: " + mincho.Equals(pencho)); Console.WriteLine("Mincho == pencho: " + (mincho == pencho)); Console.WriteLine("Mincho != pencho: " + (mincho != pencho)); Console.WriteLine(Environment.NewLine); Console.WriteLine(pencho); Console.WriteLine(Environment.NewLine); Console.WriteLine(mincho); Console.WriteLine(Environment.NewLine); var tempStudent = mincho.Clone() as Student; Console.WriteLine("Reference equals tempStudent and mincho: " + object.ReferenceEquals(tempStudent.MiddleName, mincho.MiddleName)); tempStudent.MiddleName = "Gosho"; mincho.MiddleName = "Mincho 2"; Console.WriteLine(tempStudent.MiddleName); Console.WriteLine(mincho.MiddleName); Console.WriteLine(pencho.CompareTo(mincho)); }
public static bool operator !=(Student studentFirst, Student studentSecond) { return(!(Student.Equals(studentFirst, studentSecond))); }
public static bool operator !=(Student student1, Student student2) { return(!(Student.Equals(student1, student2))); }
public static bool operator !=(Course curs1, Course curs2) { return(!(Student.Equals(curs1, curs2))); }
static void Main() { Student firstStudent = new Student("Ivan", "Ivanov", "Ivanov", "8912123434", "bul. Bulgaria 1", "0888888888", "*****@*****.**", 4, Specialty.CST, Faculty.FKSU, University.TUSofiya); Student secondStudent = new Student("Stefaniya", "Stefanova", "Stefanova", "9011115757", "bul. Al.Malinov 1", "0888555555", "*****@*****.**", 3, Specialty.EngineerDesign, Faculty.MF, University.TUSofiya); Student thirdStudent = new Student("Stefaniya", "Stefanova", "Stefanova", "9011115757", "bul. Al.Malinov 1", "0888555555", "*****@*****.**", 3, Specialty.EngineerDesign, Faculty.MF, University.TUSofiya); // Testing the ToString() method Console.WriteLine("Testing the ToString() method:"); Console.WriteLine(new string('-', 30)); Console.WriteLine(firstStudent); Console.WriteLine(secondStudent); // Testing the GetHashCode() and Equals methods Console.WriteLine("Testing the GetHashCode() and Equals() methods:"); Console.WriteLine(new string('-', 47)); Console.WriteLine("Result of the Equals() method for the third and the second student: {0}", thirdStudent.Equals(secondStudent)); Console.WriteLine("First student HashCode: " + firstStudent.GetHashCode()); Console.WriteLine("Second student HashCode: " + secondStudent.GetHashCode()); Console.WriteLine("Result of the Equals() method for the hashcodes of the first and the second student: " + firstStudent.GetHashCode().Equals(secondStudent.GetHashCode())); Console.WriteLine("Result of the Equals() method for the hashcodes of the third and the second student: " + thirdStudent.GetHashCode().Equals(secondStudent.GetHashCode())); Console.WriteLine(); // Testing the == and != operators Console.WriteLine("Testing the == and != operators:"); Console.WriteLine(new string('-', 32)); Console.WriteLine("First student == Second student: {0}", firstStudent == secondStudent); Console.WriteLine("Second student == Third student: {0}", secondStudent == thirdStudent); Console.WriteLine("First student != Second student: {0}", firstStudent != secondStudent); Console.WriteLine("Second student != Third student: {0}", secondStudent != thirdStudent); Console.WriteLine(); // Testing the Clone() method Console.WriteLine("Testing the Clone() method:"); Console.WriteLine(new string('-', 27)); Student copiedStudent = firstStudent.Clone() as Student; Console.WriteLine("First student clone == First student: {0}", copiedStudent == firstStudent); Console.WriteLine(); // Testing the CompareTo() method Console.WriteLine("Testing the CompareTo() method:"); Console.WriteLine(new string('-', 31)); Console.WriteLine("First student compared to the second student: {0}", firstStudent.CompareTo(secondStudent)); Console.WriteLine("Second student compared to the first student: {0}", secondStudent.CompareTo(firstStudent)); Console.WriteLine("Cloned student compared to the first student: {0}", copiedStudent.CompareTo(firstStudent)); }
public static void Main(string[] args) { Person pesho = new Person("Peter"); Console.WriteLine(pesho); var mincho = new Student( "Mincho", "Hristov", "Petrov", 323453, "Sofia", 0888888888, "*****@*****.**", 2, Specialty.Engines, University.TUSofia, Faculty.ComputerScience); var penka = new Student( "Penka", "Slavova", "Litova", 323453, "Varna", 0888123456, "*****@*****.**", 2, Specialty.PlasticSurgery, University.MedicalUniversity, Faculty.Chemistry); Student pencho = new Student( "Mincho", "Hristov", "Petrov", 323453, "Sofia", 0888765488, "*****@*****.**", 5, Specialty.HumanBehavior, University.UniSofia, Faculty.Psychology); Console.WriteLine("Mincho equals pencho: " + mincho.Equals(pencho)); Console.WriteLine("Mincho == pencho: " + (mincho == pencho)); Console.WriteLine("Mincho != pencho: " + (mincho != pencho)); Console.WriteLine(Environment.NewLine); Console.WriteLine(pencho); Console.WriteLine(Environment.NewLine); Console.WriteLine(mincho); Console.WriteLine(Environment.NewLine); var tempStudent = mincho.Clone() as Student; Console.WriteLine("Reference equals tempStudent and mincho: " + object.ReferenceEquals(tempStudent.MiddleName, mincho.MiddleName)); tempStudent.MiddleName = "Gosho"; mincho.MiddleName = "Mincho 2"; Console.WriteLine(tempStudent.MiddleName); Console.WriteLine(mincho.MiddleName); Console.WriteLine(pencho.CompareTo(mincho)); }