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)); }
public object Clone() { Student temp = new Student(this.FirstName, this.MiddleName, this.LastName, this.SSN, this.Address, this.Phone, this.Email); temp.UniversityInf(this.University, this.Course, this.Faculty, this.Speciality); return temp; }
static void Main() { Student student = new Student("Peter", 22); student.PropertyChanged += (sender, args) => { Console.WriteLine("Property changed: {0} (from {1} to {2})", args.Name, args.OldValue, args.NewValue); }; student.Name = "Maria"; student.Age = 19; }
static void Main(string[] args) { var student = new Student("Aleks", 21); student.OnPropertyChanged += (eventArgs) => { Console.WriteLine("Property changed: {0} (from {1} to {2})", eventArgs.PropertyName, eventArgs.OldValue, eventArgs.NewValue); }; student.Name = "Vanq"; student.Age = 25; }
static void Main() { Student st1 = new Student("Pepo", "Galev", "Gadevski", "DM-011249-783314", "avn. Wall Street 1", "0866969123", "*****@*****.**", "Practical Mathematics", Specialties.Mathematics, Faculties.MathematicsAndInformatics, Universities.SU); Student st2 = new Student("Pepo", "Galev", "Gadevski", "DM-011249-783314", "avn. Wall Street 1", "0866969123", "*****@*****.**", "Practical Mathematics", Specialties.Mathematics, Faculties.MathematicsAndInformatics, Universities.SU); Student st4 = new Student("PepoV", "Galev", "Gadevski", "DM-011249-783314", "avn. Wall Street 1", "0800000001", "*****@*****.**", "Practical Mathematics", Specialties.Mathematics, Faculties.MathematicsAndInformatics, Universities.TU); Student st5 = new Student("PepoV", "Galev", "Gadevski", "AM-011249-783314", "avn. Wall Street 1", "0800000001", "*****@*****.**", "Practical Mathematics", Specialties.Mathematics, Faculties.MathematicsAndInformatics, Universities.TU); }
static void Main() { Student someone = new Student("Pesho", 15); someone.OnPropertyChanged += (sender, eventArgs) => { Console.WriteLine("Property changed: {0} (from {1} to {2})", eventArgs.PropertyName, eventArgs.OldValue, eventArgs.NewValue); }; someone.Name = "Kristina"; someone.Age = 21; }
public static void Main() { Student student = new Student("Pesho", 23); student.OnPropertyChanged += (sender, eventArgs) => { Console.WriteLine("Property changed: {0} (from {1} to {2})", eventArgs.PropertyName, eventArgs.OldValue, eventArgs.NewValue); }; student.Name = "Maria"; student.Age = 19; }
static void Main(string[] args) { Student student = new Student("Peter", 22); student.EventChange += (eventArgs) => { Console.WriteLine("Property changed: {0} (from {1} to {2})",eventArgs.PropertyName,eventArgs.OldValue,eventArgs.NewValue); }; student.Name = "Maria"; student.Age = 19; }
static void Main() { Student student = new Student("Ivan", 22); student.PropertyChanged += (sender, eventArgs) => { Console.WriteLine("Property changed: {0} (from {1} to {2})", eventArgs.PropertyName, eventArgs.OldValue, eventArgs.NewValue); }; student.Age = 33; student.Name = "Minka"; }
public static void Main() { List<Student> students = new List<Student>(); Student gosho = new Student("Gosho", "Ivanov", "Petkov", 2048, "Sofia", "0888888888", "*****@*****.**", "First", University.Sofia_University, Faculty.Informatics, Specialty.Computer_Science); students.Add(gosho); Student pesho = new Student("Pesho", "Ivanov", "Petkov", 211, "Sofia", "0888888889", "*****@*****.**", "First", University.Sofia_University, Faculty.Informatics, Specialty.Computer_Science); // The overriden Equals() should return false as some of the properties don't match hence the overloaded "==" also returns false students.Add(pesho); students.Sort(); foreach (var student in students) { Console.WriteLine(student.ToString()); } }
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)); }
public static void Main() { var firstStudent = new Student("Ivan", "Ivanov", "Ivanov", 1234,"another adress", "+359888345678", "*****@*****.**", "Some Course", Specialty.Physics, Faculty.Mathemtics, University.MEI); var secondStudent = (Student)firstStudent.Clone(); var thirdStudent = new Student("Gosho", "Georgiev", "Ivanov", 1233, "some address", "+359888123456", "*****@*****.**", "Some Course", Specialty.Physics, Faculty.Mathemtics, University.MEI); Console.WriteLine(firstStudent); Console.WriteLine(secondStudent); Console.WriteLine(thirdStudent); Console.WriteLine("First student == second student: {0}", firstStudent == secondStudent); Console.WriteLine("First student == third student: {0}", firstStudent == thirdStudent); Console.WriteLine("First student != third student: {0}", firstStudent != thirdStudent); Console.WriteLine("First studen GetHashCode(): {0}", firstStudent.GetHashCode()); Console.WriteLine("Second studen GetHashCode(): {0}", secondStudent.GetHashCode()); Console.WriteLine("Third studen GetHashCode(): {0}", thirdStudent.GetHashCode()); Console.WriteLine(firstStudent.CompareTo(thirdStudent)); }
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 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(string[] args) { List<Student> list = new List<Student>(); //11.Count of entries created Student abc = new Student("Umur","Yuksel","yuksel@abc"); int a = list.Count; Console.WriteLine("Items created" + " : " + a); list.Add(abc); list.Sort(); foreach (var element in list) { Console.WriteLine(element); Console.ReadKey(); } }
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)); }
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 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() { Student firstStudent = new Student("Slavin", 25); Student secondStudent = new Student("Nevena", 22); firstStudent.PropertyChanged += (sender, eventArgs) => Console.WriteLine("Property cnaged: {0} (from {1} to {2})", eventArgs.Property, eventArgs.OldValue, eventArgs.NewValue); secondStudent.PropertyChanged += (sender, eventArgs) => Console.WriteLine("Property cnaged: {0} (from {1} to {2})", eventArgs.Property, eventArgs.OldValue, eventArgs.NewValue); firstStudent.Name = "Slavcho faktora"; firstStudent.Age = 26; secondStudent.Name = "Nevi stana vtora"; secondStudent.Age = 23; Console.WriteLine(); firstStudent.Name = "Slavin"; firstStudent.Age = 27; secondStudent.Name = "Nevena"; secondStudent.Age = 24; }
/* Problem 1: Define a class Student, which contains data about a student – first, middle and last name, SSN, permanent address, mobile phone e-mail, course, specialty, university, faculty. Use an enumeration for the specialties, universities and faculties. Override the standard methods, inherited by System.Object: Equals(), ToString(), GetHashCode() and operators == and !=. Problem 2: Add implementations of the ICloneable interface. The Clone() method should deeply copy all object's fields into a new object of type Student. Problem 3: Implement the IComparable<Student> interface to compare students by names (as first criteria, in lexicographic order) and by social security number (as second criteria, in increasing order). */ public static void Main() { var student = new Student( "Pesho", "Peshev", "Petkov", "029338419", "23 Elm Street", "0885100300", "*****@*****.**", "Software engineering", Speciality.Mathematics, University.TechUni, Faculty.SF); Console.WriteLine(student.ToString()); var otherStudent = student.Clone(); Console.WriteLine(otherStudent); }
static void Main(string[] args) { FileInfo f; StreamWriter w; for (int i = 0; i < 3; i++) { Console.Write("Enter Name of Student : "); string Name = Console.ReadLine(); f = new FileInfo(Name+".txt"); w = f.CreateText(); Console.Write("ID : "); string ID = Console.ReadLine(); Console.Write("Year of graduating : "); int Year = int.Parse(Console.ReadLine()); Console.Write("GPA : "); Double GPA = Convert.ToDouble(Console.ReadLine()); Student student = new Student(Name, ID, Year, GPA); w.WriteLine(student); } // w.Close(); }
static void Main() { Student firstStudent = new Student("Ivan", "Doychinov", 3435467234, 2, Specialty.ApplingMath, University.TechnicalUniversity, Faculty.MathematicalFaculty); Student secondStudent = new Student("Petar", "Mihov", 3435467234, 2, Specialty.ApplingMath, University.TechnicalUniversity, Faculty.MathematicalFaculty); Student thirdStudent = new Student("Ivan", "Doychinov", 3435467234, 2, Specialty.ApplingMath, University.TechnicalUniversity, Faculty.MathematicalFaculty); if (firstStudent != secondStudent) // it is true Console.WriteLine("{0} != {1}", firstStudent.FirstName, secondStudent.FirstName); if (firstStudent == thirdStudent) // it is true Console.WriteLine("{0} == {1}", firstStudent.FirstName, thirdStudent.FirstName); Student deeplyCloned = (Student)firstStudent.Clone(); Console.WriteLine("\nThe Cloned student is: "); Console.WriteLine(deeplyCloned); Console.WriteLine(firstStudent.CompareTo(secondStudent)); }
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 firstSudent = new Student("Pesho", "Ivanov", "Georgiev", 9003177211, "Sofia, № 411 Georgi Kalinov street", "0899471511", "*****@*****.**", 4, Specialty.ComputerSciences, University.Birmingham, Faculty.Technology); Student secondSudent = new Student("Pesho", "Peshov", "Ivanov", 9003177211, "Sofia, № 411 Georgi Kalinov street", "0877415500", "*****@*****.**", 1, Specialty.EarthSciences, University.Lancaster, Faculty.PhysicalSciences); Student thirdSudent = new Student("Ivelina", "Stamatova", "Petkovva", 9101114512, "Sofia, № 21 Georgi Kalinov street", "0899471511", "*****@*****.**", 3, Specialty.Journalism, University.Harvard, Faculty.HumanitiesSocialSciences); Student fourthSudent = new Student("Stamat", "Ivanov", "Stamatov", 9309121411, "Sofia, № 9 Georgi Kalinov street", "0899510100", "*****@*****.**", 3, Specialty.BiologicalSciences, University.Durham, Faculty.ClinicalMedicine); Console.WriteLine(firstSudent); Console.WriteLine("\nAre equals: {0}", firstSudent == secondSudent); Console.WriteLine("HashCode: {0}", thirdSudent.GetHashCode()); Console.WriteLine("Please press a key do clear the console and to continue."); Console.ReadKey(); Console.Clear(); // Clone student var newStudentClone = firstSudent.Clone(); // Change some thing in the cloning (newStudentClone as Student).FirstName = "Doncho"; (newStudentClone as Student).LastName = "Petkov"; Console.WriteLine("The cloning with some changes:\n"); Console.WriteLine(newStudentClone); Console.WriteLine("The original:\n"); Console.WriteLine(firstSudent); // Using CompareTo Console.WriteLine("Compare two student by names and SSN: {0}", firstSudent.CompareTo(secondSudent)); }
static void Main() { var firstStudent = new Student("Gosho", "Brigadirov", "Kirov", 554755, "2 Pencho street", "+3598875423664", "*****@*****.**", 5, Specialitiy.Engineering, University.TehnicalUniversity, Faculty.Mathematic); var secondStudent = new Student("Evdokiq", "Gusheva", "Musheva", 558899, "3 Nanadolnishte blv.", "029408751", "*****@*****.**", 4, Specialitiy.Biology, University.UNSS, Faculty.Biologic); Console.WriteLine(new string('*', 40)); Console.WriteLine(firstStudent.ToString()); Console.WriteLine(); Console.WriteLine("{0} hash code is {1}",firstStudent.FirstName, firstStudent.GetHashCode()); Console.WriteLine("{0} hash code is {1}",secondStudent.FirstName ,secondStudent.GetHashCode()); Console.WriteLine(new string('*', 40)); Console.WriteLine("Coping:"); Console.WriteLine(new string('*', 40)); var AntoanCopy = firstStudent.Clone(); Console.WriteLine(AntoanCopy); Console.WriteLine(new string('*', 40)); Console.WriteLine("Comparing"); Console.WriteLine(new string('*', 40)); Console.WriteLine(firstStudent.CompareTo(secondStudent)); }
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)); }
static void Main() { Student FirstStudent =new Student("Ivan", "Ivanov", 12154545, Specialty.Informatics , University.SofiaUniversity, Faculty.Mathematics ); Student SecontStudent = new Student("Georgi", "Georgiev", 121545545, Specialty.Mathematics, University.SofiaUniversity, Faculty.Mathematics); Student ThirtStudent = new Student("Ivan", "Ivanov", 12154545, Specialty.SoftwareEngineering, University.TehnicalUniversity, Faculty.Informatics, "second", "MiddleOfNothing St", "0897456123", "*****@*****.**", "Georgiev" ); Console.WriteLine("Is student equals:"); Console.WriteLine(FirstStudent == SecontStudent); Console.WriteLine(FirstStudent==ThirtStudent); Console.WriteLine(); Console.WriteLine(); Console.WriteLine(); Console.WriteLine("Compare two students"); Console.WriteLine(FirstStudent.CompareTo(ThirtStudent)); Console.WriteLine(); Console.WriteLine("Data for student:"); Console.WriteLine(ThirtStudent.ToString()); Console.WriteLine(); Console.WriteLine("HashCode:"); Console.WriteLine(FirstStudent.GetHashCode()); Console.WriteLine(SecontStudent.GetHashCode()); }
/// <summary> /// Deep cloning of Student type instance /// </summary> /// <returns></returns> public object Clone() { Student result = new Student(); // Collects all values of all properties var queue = new Queue<object>(); foreach (var prop in this.GetType().GetProperties()) { if (prop.PropertyType == typeof(int)) { queue.Enqueue(prop.GetValue(this)); } else { queue.Enqueue((prop.GetValue(this) as string).Clone()); } } // Save all data to the new object foreach (var prop in result.GetType().GetProperties()) { prop.SetValue(result, queue.Dequeue()); } return result; }
public static bool operator !=(Student firstStudent, Student secondStudent) { return(!Student.Equals(firstStudent, secondStudent)); }
//Problem 3. IComparable //Implement the IComparable<Student> interface to compare students by names (as first criteria, in lexicographic order) //and by social security number (as second criteria, in increasing order). public int CompareTo(Student otherStudent) { var StudentName = string.Concat(this.FirstName, this.LastName); var otherStudentName = string.Concat(otherStudent.FirstName, otherStudent.LastName); var comparisonResult = StudentName.CompareTo(otherStudentName); if (comparisonResult == 0) { return this.SSN.CompareTo(otherStudent.SSN); } return comparisonResult; }
//Problem 2. ICloneable // Add implementations of the ICloneable interface. The Clone() method should deeply copy all object's fields into a new object of type Student. public object Clone() { Student deepCopy = new Student(this.firstName, this.LastName, this.SSN, this.SpecialtyStudent, this.UniversityStudent, this.FacultyStudent, this.Course, this.Address, this.MobilePhone, this.Email, this.MiddleName); return deepCopy; }