当前位置: 首页>>代码示例>>C#>>正文


C# Student.CompareTo方法代码示例

本文整理汇总了C#中Student.CompareTo方法的典型用法代码示例。如果您正苦于以下问题:C# Student.CompareTo方法的具体用法?C# Student.CompareTo怎么用?C# Student.CompareTo使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Student的用法示例。


在下文中一共展示了Student.CompareTo方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Main

        static void Main(string[] args)
        {
            //Create 3 test students
            Student firstStudent = new Student("Gosho", "Ivanov", "Peshov", "11122", "Gosho Street", "02423423", "[email protected]", 1,
                Universities.HarvardUniversity, Faculties.FacultyOfComputerScience ,Specialties.ComputerGraphics);
            Student secondStudent = new Student("Ivan", "Georgiev", "Alexandrov", "15624", "Pesho Street", "09415743", "[email protected]", 2,
                Universities.MassachusettsInstituteofTechnology, Faculties.FacultyOfComputerScience, Specialties.ArtificialIntelligence);
            Student thirdStudent = new Student("Gosho", "Ivanov", "Peshov", "10021", "Ivan Street", "931234", "[email protected]", 1,
                Universities.SofiaUniversity, Faculties.FacultyOfComputerScience, Specialties.ComputerProgramming);

            //Clone a student from the first
            Student clonedStundent = firstStudent.Clone() as Student;

            Console.WriteLine(firstStudent.ToString());
            Console.WriteLine(secondStudent.ToString());
            Console.WriteLine(thirdStudent.ToString());
            Console.WriteLine("First student == Second Student ?:{0}", firstStudent == secondStudent);
            Console.WriteLine("First student != Third Student ?:{0}", firstStudent != thirdStudent);
            Console.WriteLine("First student Equals Cloned Student ?:{0}", firstStudent.Equals(clonedStundent));
            Console.WriteLine("First student compared to Second Student (in ints): {0}", firstStudent.CompareTo(secondStudent));
            Console.WriteLine("First student compared to Third Student (in ints): {0}", firstStudent.CompareTo(thirdStudent));
            Console.WriteLine("First student compared to Cloned Student (in ints): {0}", firstStudent.CompareTo(clonedStundent));

            //Before change
            Console.WriteLine("Is first student number equal to cloned first student number ? {0}", firstStudent.MobilePhone == clonedStundent.MobilePhone);
            //The first student changes his number
            firstStudent.MobilePhone = "088888888";

            //Compare the cloned first student to the changed one
            Console.WriteLine("Is first student number equal to cloned first student number ? {0}", firstStudent.MobilePhone == clonedStundent.MobilePhone);
        }
开发者ID:NikolayGenov,项目名称:TelerikAcademy,代码行数:31,代码来源:TestClass.cs

示例2: 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));
    }
开发者ID:MarKamenov,项目名称:TelerikAcademy,代码行数:27,代码来源:Program.cs

示例3: Main

    static void Main(string[] args)
    {
        //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 !=.
        //Add implementations of the ICloneable interface. The Clone() method should deeply copy all
        //object's fields into a new object of type Student.
        //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).

        //Making student and test override ToString method
        Student peter = new Student("Peter", "Ivanov", "Petrov", 12764397, "Sofia,Mladost1,Al. Malinov str.", 0889888888,
            "[email protected]", 2, Universities.SofiaUniversity, Faculties.HistoryFaculty, Specialties.History);
        Console.WriteLine(peter);
        Console.WriteLine();

        //Make second student who is deep clone of the first one and test this
        Student ivo = peter.Clone();
        Console.WriteLine(ivo);
        ivo.FirstName = "Joro";
        Console.WriteLine(ivo.FirstName);
        Console.WriteLine(peter.FirstName);
        Console.WriteLine();

        //Testing override method CompareTo
        Console.WriteLine(peter.CompareTo(ivo));
        ivo.FirstName = "Peter";
        Console.WriteLine(peter.CompareTo(ivo));
    }
开发者ID:Jarolim,项目名称:TelerikAcademy-1,代码行数:30,代码来源:Program.cs

示例4: 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));
        }
开发者ID:AYankova,项目名称:CSharp,代码行数:28,代码来源:StudentsTest.cs

示例5: Main

    static void Main()
    {
        Student firstStudent = new Student("Mateo", "Needham", " Brinson", 9999999, "Street 5", 500001, University.NBU, Specialty.Math, Faculty.Mathematics);
        Student secondStudent = firstStudent.Clone();
        Student thirdStudent = new Student("Chris", "Norwood", " Varela", 8888888, "Street 125", 600001, University.TU, Specialty.Law, Faculty.Law);

        Console.WriteLine(firstStudent); // ToString
        Console.WriteLine(firstStudent.CompareTo(secondStudent)); // CompareTo
        Console.WriteLine(firstStudent.CompareTo(thirdStudent)); // CompareTo
    }
开发者ID:hristian-dimov,项目名称:TelerikAcademy,代码行数:10,代码来源:StudentTest.cs

示例6: Main

    static void Main(string[] args)
    {
        Student student1 = new Student("nameF", "nameM", "nameFam", 555, "Address", 033, "FA",
           Universities.Universities1, Specialty.Specialty2, Faculty.Faculty3);
        Student student2 = new Student("nameF", "nameM", "nameFam", 555, "Address", 0331, "FA",
           Universities.Universities1, Specialty.Specialty2, Faculty.Faculty3);
        //It is looking for same ssn
        Console.WriteLine("Are the students equal?");
        Console.WriteLine(student1.Equals(student2));
        //!=
        Console.WriteLine(student1 != student2);
        //to string
        Console.WriteLine("---------------------------------------------------------------------");
        Console.WriteLine(student1.ToString());
        Console.WriteLine("Clone----------------------------------------------------------------");
        // firstName is not private because I want to try this things
        Student clStudent= student1.Clone() as Student;
        //check for first and last name of the clone student
        Console.WriteLine(clStudent.FirstName);
        Console.WriteLine(clStudent.LastName);
        //check for string builder used in ToString
        Console.WriteLine(clStudent.ToString());
        //check what will happen if I rename fistrName of  the clone student
        clStudent.FirstName = "RenameName";
        Console.WriteLine("Rename--------------------------------------------------------------");
        Console.WriteLine("The original name is :{0}",student1.FirstName);
        Console.WriteLine("The new name is      :{0}",clStudent.FirstName);
        //you can not have two people with same SSN, but in this case You can :)
        Console.WriteLine(clStudent.Equals(clStudent));
        Console.WriteLine("Rename and ToString------------------------------------------------");
        Console.WriteLine(clStudent.ToString());
        Console.WriteLine("");
        Console.WriteLine("Ex.3---------------------------------------------------------------");

        Student student3 = new Student("A", "nameM", "nameFam", 455, "Address", 033, "FA",
           Universities.Universities1, Specialty.Specialty2, Faculty.Faculty3);
        Student student4 = new Student("A", "nameM", "nameFam", 555, "Address", 0331, "FA",
           Universities.Universities2, Specialty.Specialty2, Faculty.Faculty2);
        if (student3.CompareTo(student4)== 0)
        {
            Console.WriteLine("Student3 is equal to student4");
        }
        else if (student3.CompareTo(student4) < 0)
        {
            Console.WriteLine("It must be in lexicographic order ");
            Console.WriteLine("First student is : {0}",student3);
            Console.WriteLine("Second student is: {0}",student4);
        }
        else
        {
            Console.WriteLine("It must be in lexicographic order ");
            Console.WriteLine("First student is : {0}", student4);
            Console.WriteLine("Second student is: {0}", student3);
        }
    }
开发者ID:naturalna,项目名称:OOPPrinciples,代码行数:55,代码来源:StudentEntryPoint.cs

示例7: Main

        static void Main(string[] args)
        {
            Console.Title = "Students";

            Student st1 = new Student("Ivan", "Petkov", "Minev", "123456", "ul.Nishava №1", "+359883554422", "[email protected]", 3, Specialty.ComputerScientce, University.SofiaUniversity, Faculty.Computers);
            var st2 = st1.Clone();

            Console.ForegroundColor = ConsoleColor.Yellow;
            Console.WriteLine(st1);
            Console.WriteLine();

            Console.ForegroundColor = ConsoleColor.Cyan;
            Console.WriteLine(st2);
            Console.WriteLine();

            Console.ForegroundColor = ConsoleColor.Red;
            Console.WriteLine("Student1 equals student2 ? : {0}", st1.Equals(st2));
            Console.WriteLine("Student1 compare to student2 ? : {0}", st1.CompareTo(st2));

            Console.WriteLine();

            st2.FirstName = "Georgi";

            Console.ForegroundColor = ConsoleColor.Yellow;
            Console.WriteLine(st1);
            Console.WriteLine();

            Console.ForegroundColor = ConsoleColor.Cyan;
            Console.WriteLine(st2);
            Console.WriteLine();

            Console.ForegroundColor = ConsoleColor.Red;
            Console.WriteLine("Student1 equals student2 ? : {0}", st1.Equals(st2));
            Console.WriteLine("Student1 compare to student2 ? : {0}", st1.CompareTo(st2));
            Console.WriteLine();

            st1.FirstName = "Georgi";
            st2.SSN = "123459";
            st2.Address = "ul. James Bourchier №123";

            Console.ForegroundColor = ConsoleColor.Yellow;
            Console.WriteLine(st1);
            Console.WriteLine();

            Console.ForegroundColor = ConsoleColor.Cyan;
            Console.WriteLine(st2);
            Console.WriteLine();

            Console.ForegroundColor = ConsoleColor.Red;
            Console.WriteLine("Student1 equals student2 ? : {0}", st1.Equals(st2));
            Console.WriteLine("Student1 compare to student2 ? : {0}", st1.CompareTo(st2));

            Console.WriteLine();
            Console.ResetColor();
        }
开发者ID:nikolay-radkov,项目名称:Telerik-Academy,代码行数:55,代码来源:Demo.cs

示例8: 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!");
            }
        }
开发者ID:smihaylovit,项目名称:TelerikAcademy,代码行数:55,代码来源:StudentsInformationalCenterDemo.cs

示例9: Main

        static void Main(string[] args)
        {
            bool result = false;
            int testNum = 0;
            Student st1 = new Student("Pe6o","Pe6ov", "Peshistia", "8514897589");
            Student st2 = (Student)st1.Clone(); // deep copy student st1 to st2
            Student st3 = new Student("Angel", "Yavorov", "Angelov", "123450");

            st2.Ssn= (ulong.Parse(st2.Ssn) + 1).ToString(); // increase st2 ssn with 1

            testNum = 1;
            int returned = st1.CompareTo(st2);
            result = (returned == -1) ? true : false;
            PrintResult(testNum, result);

            testNum = 2;
            st2.Ssn = (ulong.Parse(st2.Ssn) - 2).ToString();
            returned = st1.CompareTo(st2);
            result = (returned == 1) ? true : false;
            PrintResult(testNum, result);

            testNum = 3;
            st2.Ssn = (ulong.Parse(st2.Ssn) + 1).ToString();
            returned = st1.CompareTo(st2);
            result = (returned == 0) ? true : false;
            PrintResult(testNum, result);

            testNum = 4;
            returned = st1.CompareTo(st3);
            result = (returned == 1) ? true : false;
            PrintResult(testNum, result);

            testNum = 5;
            st2 = (Student)st1.Clone();
            result = st1 == st2;
            PrintResult(testNum, result);

            testNum = 6;
            result = !(st1 == st3);
            PrintResult(testNum, result);

            testNum = 7;
            result = st1 != st3;
            PrintResult(testNum, result);

            testNum = 8;
            result = !(st1 != st2);
            PrintResult(testNum, result);

            testNum = 9;
            string resultStr = st1.ToString();
            string expectedStr = "Pe6o Peshistia, SSN = 8514897589";
            result = (resultStr == expectedStr) ? true : false;
            PrintResult(testNum, result);
        }
开发者ID:reddogyy,项目名称:TelerikAcademy,代码行数:55,代码来源:TEST.cs

示例10: 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
        }
开发者ID:viktorD1m1trov,项目名称:T-Academy,代码行数:31,代码来源:MainMethodHere.cs

示例11: 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);
        }
开发者ID:BobbyBorisov,项目名称:TelerikAcademy,代码行数:32,代码来源:StudentTest.cs

示例12: Main

    static void Main()
    {
        Student firstStudent = new Student("gesho", "goshev", "petrov", "999", "burgas", 1234,
              "[email protected]", 3, Specialty.Banker, Univesity.BurgasFreeUniversity, Faculty.BankovoDelo);

          Student secondStudent = new Student("pesho", "goshev", "petrov", "123", "burgas", 1234,
              "[email protected]", 3, Specialty.Banker, Univesity.BurgasFreeUniversity, Faculty.BankovoDelo);

          bool areEqual = Student.Equals(firstStudent, secondStudent);
          Console.WriteLine("The first and the second student are equal: {0}", areEqual);

          if (firstStudent == secondStudent)
          {
              Console.WriteLine("The students are equal.");
          }

          if (firstStudent != secondStudent)
          {
              Console.WriteLine("The students are NOT equal.");
          }

          Student copiedStudent = firstStudent.Clone() as Student;
          Console.WriteLine(copiedStudent.ToString());

          Console.WriteLine(firstStudent.CompareTo(secondStudent)); //gesho is lexicographically before pesho, so negative result is expected.
    }
开发者ID:peterlambov,项目名称:CSharp,代码行数:26,代码来源:Program.cs

示例13: 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
        }
开发者ID:MarinMarinov,项目名称:C-Sharp-OOP,代码行数:28,代码来源:TheMain.cs

示例14: 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
    }
开发者ID:NK-Hertz,项目名称:Telerik-Academy-2014,代码行数:28,代码来源:StudentExample.cs

示例15: Main

    static void Main()
    {
        Student student1 = new Student("Georgi", "Petrov", "12345", "0999999999", Specialty.ArtificialIntelligence);
        Student student2 = new Student("Nikolai", "Atanasov", "21345", "0888888888", Specialty.Combinatorics);

        if (student1 == student2)
        {
            Console.WriteLine("Students are equel.");
        }
        else
        {
            Console.WriteLine("Students are not equel.");
        }
        Console.WriteLine();

        // Clone
        Student studentClone = student1.Clone();
        Console.WriteLine(studentClone);
        studentClone.FirstName = "Mariika";
        Console.WriteLine();
        Console.WriteLine(student1.FirstName);
        Console.WriteLine(studentClone.FirstName);
        Console.WriteLine();

        // CompareTo() - result = -1 (Georgi < Nikolai)
        if (student1.CompareTo(student2) >= 0)
        {
            Console.WriteLine("Georgi");
        }
        else
        {
            Console.WriteLine("Nikolai");
        }
    }
开发者ID:GStoykov,项目名称:TelerikAcademyHomeworks,代码行数:34,代码来源:MainProgram.cs


注:本文中的Student.CompareTo方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。