本文整理汇总了C#中Student.Clone方法的典型用法代码示例。如果您正苦于以下问题:C# Student.Clone方法的具体用法?C# Student.Clone怎么用?C# Student.Clone使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Student
的用法示例。
在下文中一共展示了Student.Clone方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: 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);
}
示例2: 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);
}
示例3: 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.
}
示例4: 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
}
示例5: 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));
}
示例6: 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");
}
}
示例7: 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
}
示例8: Main
public static void Main(string[] args)
{
Student pesho = new Student("Petur", "Ivanov", "Petrov", 8849282128, "Sofia jk Mladost", "088 888 888", "[email protected]", "first", Specialties.ComptuterScience, Universities.TU, Faculties.Science);
Student misho = pesho.Clone();
Student petur = pesho.Clone();
petur.Ssn = 8849282129; // changing SSN to be greater
misho.FirstName = "Mihail";
Console.WriteLine(misho.Equals(pesho));
var students = new List<Student> { petur, pesho, misho };
students.Sort(); // sorting students using IComparable<Student>
Console.WriteLine(string.Join("\n\n", students)); // Printing sorted student
}
示例9: Main
/*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 !=.
*/
static void Main()
{
//initialize students
Student s = new Student("Ivan", "Ivanov", "Ivanov", "1713218", Specialty.Mathematics, University.SofiaUni, Faculty.FMI);
Student p = new Student("Ivan", "Ivanov", "Ivanov", "713218", Specialty.Mathematics, University.SofiaUni, Faculty.FMI);
s.Address = "sss";
s.E_mail = "smail";
//test Equals()
Console.WriteLine(p);
Console.WriteLine();
Console.WriteLine(s);
Console.WriteLine();
Console.WriteLine(s.Equals(p));
Console.WriteLine();
//test Clone()
Student k = s.Clone();
k.Faculty = Faculty.FE;
k.Address = "kkkkk";
k.E_mail = "kmail";
Console.WriteLine(k.ToString());
//test CompareTo()
Console.WriteLine("\nCompareTo:");
Student c = new Student("Ivan", "Ivanov", "Ivanov", "13218", Specialty.Mathematics, University.SofiaUni, Faculty.FMI);
Console.WriteLine(c.CompareTo(k));
}
示例10: 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
}
示例11: Main
public static void Main()
{
List<Student> studentList = new List<Student>()
{
new Student("Nikolay", "Dimitrov", "Kostadinov", "7711240547"),
new Student("Stoyan", "Ivanov", "Petrov", "8506148485", "Maria Luiza N25", "0885698651", "[email protected]", (short)2, Specialties.ETM, Universities.TUV, Faculties.FE),
new Student("Stoyan", "Ivanov", "Petrov", "7608128816"),
new Student("Ivan", "Ivanov", "Georgiev", "9608152138")
};
studentList.Sort();
foreach (var item in studentList)
{
Console.WriteLine(item);
}
Student baseStudent = new Student(
"Stoyan",
"Ivanov",
"Petrov",
"8506148485",
"Maria Luiza N25",
"0885698651",
"[email protected]",
(short)2,
Specialties.ETM,
Universities.TUV,
Faculties.FE);
Student newStudent = baseStudent.Clone();
Console.WriteLine(studentList[1].GetHashCode() + " -- " + newStudent.GetHashCode() + " => " + studentList[1].GetHashCode().Equals(newStudent.GetHashCode()));
Console.WriteLine(studentList[1].Equals(newStudent));
}
示例12: Main
static void Main()
{
Console.WriteLine("Tasks 01 to 03 - Implementing Student class");
Student student1 = new Student("Pesho Peshov Peshistia", 123456789); // sets student1 names and SSN
student1.Specialty = Specialties.SoftwareEngineering; // sets Specialty, Faculty and University
student1.Address = "Sofia, Kriva Bara 17"; // sets address
student1.EMail = "[email protected]"; // sets e-mail
student1.Phone = "+359 878 878 878"; // sets phone
Console.WriteLine("\r\n" + student1);
Student student2 = new Student("Gosho Goshov Goshistia", 987654321); // the same to student2
student2.Specialty = Specialties.UrbanPlanning;
student2.Address = "Sofia, Prava Reka 171"; // sets address
student2.EMail = "[email protected]"; // sets e-mail
student2.Phone = "+359 898 898 898"; // sets phone
Console.WriteLine("\r\n" + student2);
Student student3 = (Student)student2.Clone(); // student2 is also a student 3 in other University
student3.University = Universities.SU;
student3.Faculty = Faculties.FMI;
student3.Specialty = Specialties.Mathematics;
Console.WriteLine("\r\nLast Student has Cloned and Specialty changed\r\n\r\n" + student3);
Console.WriteLine("\r\nAre last two students equal? - " + (student2 == student3));
Console.WriteLine("\r\nPress Enter to finish");
Console.ReadLine();
}
示例13: 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();
}
示例14: 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));
}
示例15: Main
static void Main()
{
Student studOne = new Student("Nikolai", "Iliev", "Kirilov", 8741, "Sofiq", 0884125741, "[email protected]", 3,
Specialty.Telecommunications, University.SU, Faculty.Telecommunications);
Student studTwo = new Student("Stanislav", "Krasimirov", "Ivanov", 2478, "Varna", 0894715687, "[email protected]", 1,
Specialty.Mathematics, University.VINS, Faculty.Mathematics);
Student studThree = new Student("Nikolai", "Iliev", "Kirilov", 8741, "Sofiq", 0884125741, "[email protected]", 3,
Specialty.ArtsOfMarketing, University.VINS, Faculty.Business);
Console.ForegroundColor = ConsoleColor.Green;
Console.WriteLine("StudOne equal StudTwo: {0}" , studOne.Equals(studTwo));
Console.WriteLine("StudOne equal StudThree: {0}", studOne.Equals(studThree));
Console.WriteLine();
Console.WriteLine("StudOne == StudTwo: {0}", studOne == studTwo);
Console.WriteLine("StudOne == StudThree: {0}", studOne == studThree);
Console.WriteLine();
Console.WriteLine("StudOne HashCode: {0}", studOne.GetHashCode());
Console.WriteLine("StudTwo HashCode: {0}", studTwo.GetHashCode());
Console.WriteLine();
Console.WriteLine("StudOne Deep Clone in StudFour...");
Student studFour = studOne.Clone();
Console.WriteLine();
Console.WriteLine("Print StudFour: ");
Console.ResetColor();
Console.WriteLine(studFour);
Console.ForegroundColor = ConsoleColor.Green;
Console.WriteLine("StudOne compare to StudTwo: {0}", studOne.CompareTo(studTwo));
}