public static void TypeConversion() { // SAMPLE: Type conversion - implicit StudentStruct studentStruct = new StudentStruct("Gandalf", "Grey"); StudentClass studentClass = studentStruct; Console.WriteLine("StudentStruct studentStruct = new StudentStruct(\"Gandalf\", \"Grey\");"); Console.WriteLine("StudentClass studentClass = studentStruct;"); Console.WriteLine($"studentClass.GetStudentDetails() = {studentClass.GetStudentDetails()}"); }
public static void TestStudentClass() { StudentClass student1 = new StudentClass(); StudentClass.StudentCount += 1; student1.firstName = "Jon"; student1.lastName = "Snow"; student1.schoolName = "Night's Watch"; student1.grade = 4; // knows nothing // SAMPLE: Class constructor StudentClass student2 = new StudentClass("Tyrion", "Lannister", "Școala vieții", 10); StudentClass.StudentCount += 1; // SAMPLE: Method overloading StudentClass student3 = new StudentClass("New", "Student", "School"); StudentClass.StudentCount += 1; // SAMPLE: Named parameters StudentClass student4 = new StudentClass(lastName: "Last", schoolName: "School", firstName: "First"); // SAMPLE: Static fields // Wont' work. static variables are contained by the class itself not by its instances // student4.StudentCount += 1; // This will work fine as the field belongs to the class itself StudentClass.StudentCount += 1; Console.WriteLine($"student1.FirstName = {student1.firstName}"); Console.WriteLine($"student2.FirstName = {student2.firstName}"); Console.WriteLine($"student3.SchoolName = {student3.schoolName}"); Console.WriteLine($"StudentClass.StudentCount = {StudentClass.StudentCount}"); Console.WriteLine(); // SAMPLE: Class methods - call Console.WriteLine($"student2.GetStudentDetails() = \"{student2.GetStudentDetails()}\""); }