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


C# Student.ToString方法代码示例

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


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

示例1: 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

示例2: Main

        static void Main()
        {
            var student1 = new Student("John", "Atanasov", "421586353");

            var studentEqual = new Student("John", "Atanasov", "421586353");
            Console.WriteLine("Different objects with the same properties are equal: {0}",student1.Equals(studentEqual));
            Console.WriteLine();

            Student student1DeepCopy = student1.Clone();
            Console.WriteLine("The copy and the original are the same: {0}", student1.Equals(student1DeepCopy));
            Console.WriteLine("The copy reference the original -> " + ReferenceEquals(student1, student1DeepCopy));
            Console.WriteLine();

            var student2 = new Student("John", "Atanasov", "421586353");
            var student3 = new Student("Peter", "Nikolov", "245124749");
            CompareStudents(student1, student2);
            CompareStudents(student1, student3);
            CompareStudents(student2, student3);
            Console.WriteLine();

            Console.WriteLine(student1.ToString());
            Console.WriteLine();

            student1.MiddleName = "Ivanov";
            student1.MobilePhone = "0885123456";
            student1.Faculty = Faculty.Bachelor;
            student1.University = University.SU;
            Console.WriteLine(student1.ToString());
            Console.WriteLine();
        }
开发者ID:cvet-,项目名称:Telerik_Academy,代码行数:30,代码来源:Program.cs

示例3: Main

        public static void Main()
        {
            Student firstStudent = new Student("Pesho", "Georgiev", "Ivanov", "Sofia", "+3849384398",
                "[email protected]", 3122, Specialties.Telecommunications, Universities.TU, Faculties.Law);

            Student secondStudent = new Student("Dancho", "Ivanov", "Petrov", "Plovdiv", "039483439",
                "[email protected]", 23453, Specialties.IT, Universities.NBU, Faculties.Mathematics);

            Console.WriteLine("First student HashCode: " + firstStudent.GetHashCode());
            Console.WriteLine("Second student HashCode: " + secondStudent.GetHashCode());
            Console.WriteLine("First student equals second student: " + firstStudent.Equals(secondStudent));
            Console.WriteLine("First student == second student: " + (firstStudent == secondStudent));
            Console.WriteLine("First student != second student: " + (firstStudent != secondStudent));
            Console.WriteLine();
            Console.WriteLine(secondStudent.ToString());
            Console.WriteLine();

            Student thirdStudent = (Student)secondStudent.Clone();

            Console.WriteLine("Second student == third student: " + (secondStudent == thirdStudent));
            Console.WriteLine("Second student != third student: " + (secondStudent != thirdStudent));
            Console.WriteLine("Second student.CompareTo(third student): " + secondStudent.CompareTo(thirdStudent));
            Console.WriteLine("First student.CompareTo(Second student): " + firstStudent.CompareTo(secondStudent));
            Console.WriteLine(firstStudent.ToString());
            Console.WriteLine(secondStudent.ToString());
            Console.WriteLine(thirdStudent.ToString());
        }
开发者ID:etcet1,项目名称:TelerikAcademy,代码行数:27,代码来源:StudentTest.cs

示例4: Main

        private static void Main()
        {
            try
            {
                Student pesho = new Student("Pesho Georgiev");
                Student gosho = new Student("Gosho Ivanov");
                Student misho = new Student("Misho Cekov");
                Student sasho = new Student("Sasho Kostov");

                Course telerikAcademy = new Course("Telerik Academy");
                Course webProgramming = new Course("Web Programming");

                webProgramming.AddStudent(sasho);

                telerikAcademy.AddStudent(pesho);
                telerikAcademy.AddStudent(gosho);
                telerikAcademy.AddStudent(misho);

                telerikAcademy.RemoveStudent(gosho);
                Console.WriteLine(gosho.ToString() + " was removed from course.");

                Console.WriteLine("Courses:");
                Console.WriteLine(telerikAcademy);

                School freeSchool = new School("School of Computer Sciences");
                freeSchool.AddCourse(webProgramming);
                freeSchool.AddCourse(telerikAcademy);
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
            }
        }
开发者ID:niki-funky,项目名称:Telerik_Academy,代码行数:33,代码来源:Demo.cs

示例5: Student_ToStringTest

 public void Student_ToStringTest()
 {
     string name = "Pesho";
     int id = 12345;
     Student testStudent = new Student(name, id);
     Assert.AreEqual("Student Pesho, Unique number 12345;", testStudent.ToString());
 }
开发者ID:kris4o1993,项目名称:Telerik-Academy,代码行数:7,代码来源:StudentTest.cs

示例6: 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

示例7: Main

        static void Main(string[] args)
        {
            // test the constructor with initializerz
            Student firstStudent = new Student("Petar", "Ivanov", "Georgiev", "3210-2112-35435",
                "Sofia, Vasil Levski Str., No 201", "0888197143",
                "[email protected]", "Java Programming", Specialty.ComputerScience,
                Faculty.MathsAndInformatics, University.SofiaUniversity);

            // test the Clone() method
            Student cloned = (Student)firstStudent.Clone();

            // test the ToString() method
            Console.WriteLine("Information about the first student:");
            Console.WriteLine(firstStudent.ToString());

            Console.WriteLine("Information about the cloned student: ");
            Console.WriteLine(cloned.ToString());

            //test the equality operator
            Console.WriteLine("The two students are equal: {0}",
                firstStudent == cloned);

            cloned.MiddleName = "Dimitrov";
            cloned.SSN = "98978989-8984934-0435";

            //test the CompareTo() method
            Console.WriteLine("Some properties were changed. CompareTo returns: {0}",
                firstStudent.CompareTo(cloned));
        }
开发者ID:BlueForeverI,项目名称:OOPHomework,代码行数:29,代码来源:StudentTest.cs

示例8: TestStudentToString1

        public void TestStudentToString1()
        {
            Student kentBeck = new Student("Kent Beck");

            Assert.AreEqual(
                string.Format("{{ Id = {0}, Name = Kent Beck }}", kentBeck.Id),
                kentBeck.ToString(),
                "Student.ToString() is not correct.");
        }
开发者ID:Ivan-Dimitrov-bg,项目名称:.Net-framework,代码行数:9,代码来源:StudentTests.cs

示例9: ToStringTest

 public void ToStringTest()
 {
     string name = "Maria Petrova";
     int uniqueNumber = 12345;
     Student student = new Student(name, uniqueNumber);
     string expected = "Student Maria Petrova, ID 12345; ";
     string actual;
     actual = student.ToString();
     Assert.AreEqual(expected, actual);
 }
开发者ID:krumov,项目名称:telerik,代码行数:10,代码来源:StudentTest.cs

示例10: ToStringTest

 public void ToStringTest()
 {
     string name = "Pesho Petrov";
     int classNumber = 12345;
     Student student = new Student(name, classNumber);
     string expected = "Student Pesho Petrov, ID 12345; ";
     string actual;
     actual = student.ToString();
     Assert.AreEqual(expected, actual);
 }
开发者ID:mariya-ivanova,项目名称:KPK-Homework,代码行数:10,代码来源:StudentTest.cs

示例11: 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

示例12: 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

示例13: Comparison

        /// <summary>
        ///     Comparisons the specified a.
        /// </summary>
        /// <param name="a">a.</param>
        /// <param name="b">The b.</param>
        /// <returns></returns>
        public static int Comparison(Student a, Student b)
        {
            // The Students Do not have the same Name
            // Sort by name
            if (!a.Name.Equals(b.Name)) return a.CompareTo(b);

            // The students have the same type
            return a.ToString().Equals(b.ToString())
                ? a.Number.CompareTo(b.Number)
                : TypeValue(a.GetType()).CompareTo(TypeValue(b.GetType()));
        }
开发者ID:davericher,项目名称:cst8256,代码行数:17,代码来源:StudentSorter.cs

示例14: Main

    static void Main(string[] args)
    {
        Student firstStudent = new Student("Petko", "Georgiev", "Karaulanov", 7811125447, "Makedonska 55", 0888880088, "[email protected]",
                "3", Specialties.HTML, Faculties.Economics, Universitaties.FUB);

            Console.WriteLine(firstStudent.ToString());

            Student clonedFirst = firstStudent.Clone();

            Console.WriteLine(clonedFirst.ToString());

            Console.WriteLine("The two students are equals:{0}",firstStudent.Equals(clonedFirst));
    }
开发者ID:KaloyanBobev,项目名称:OOP,代码行数:13,代码来源:TestProgram.cs

示例15: Main

        static void Main(string[] args)
        {
            var studentOne = new Student("Ivan", "Georgiev", "Dimitrov", "0123456789", "Sofia,Some str,15", "35988888888", "[email protected]", 4, Specialties.Chemistry, Universities.SofiaUniversity, Faculties.Science);
            var studentTwo = new Student("George", "Dimitrov", "Dimitrov", "9876543210", "Sofia,Some str,25", "077777777", "[email protected]", 7, Specialties.Engineering, Universities.TechnicalUniversity, Faculties.MechanicallEngineering);

            //Showing overwritten ToString()
            Console.WriteLine(studentOne.ToString());

            //Task 2: Test
            var studentThree = studentOne.Clone();
            Console.WriteLine(studentThree.ToString());

            //Task 3: Test will return 0 which shows that they are same
            Console.WriteLine(studentOne.CompareTo(studentThree));
        }
开发者ID:aleks-todorov,项目名称:HomeWorks,代码行数:15,代码来源:Application.cs


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