public override void printCar() { stStudent gg = new stStudent(); Console.WriteLine($"Car Price: {Price.ToString("N0")} \t\t Car Weight: {Weight.ToString("N0")}"); }
private static void part3() { var student = new { Id = 1.5, FirstName = "James", LastName = "Bond" }; Console.WriteLine(student.Id); //output: 1 Console.WriteLine(student.FirstName); //output: James Console.WriteLine(student.LastName); //output: Bond //Anonymous objects are ready only //student.Id = 2;//Error: cannot chage value //student.FirstName = "Steve";//Error: cannot chage value //nested Anonymous type object var student2 = new { Id = 1, FirstName = "James", LastName = "Bond", Address = new { Id = 1, City = "London", Country = "UK" } }; Console.WriteLine(student2.Address.City); IList <Student> studentList = new List <Student>() { new Student() { StudentID = 1, StudentName = "John", age = 18 }, new Student() { StudentID = 2, StudentName = "Steve", age = 21 }, new Student() { StudentID = 3, StudentName = "Bill", age = 18 }, new Student() { StudentID = 4, StudentName = "Ram", age = 20 }, new Student() { StudentID = 5, StudentName = "Ron", age = 21 } }; //Anonymous type objects are most commonly used to select a subset of a collection like below var students = from s in studentList select new { Id = s.StudentID, Name = s.StudentName }; foreach (var stud in students) { Console.WriteLine(stud.Id + "-" + stud.Name); } IList <Student> studentList2 = studentList;//this simply copy the pointer of studentList into the studentList2 object. so they point to the same values. whatever change we made on values, will be reflected to the both objects beacuse they point to the same values. they are just memory addreses studentList2[2].age = 100; Console.WriteLine($"studentList index 2 age = {studentList[2].age} and studentList2 index 2 age = {studentList2[2].age}"); stStudent st_student_1 = new stStudent { irAge = 21, srName = "Test Student" }; stStudent st_student_2 = st_student_1;//this is copying values since it is struct type. on classes it just copies reference not the values st_student_2.irAge = 100; Console.WriteLine($"st_student_1 age = {st_student_1.irAge} and st_student_2 age = {st_student_2.irAge}"); for (int i = 0; i < 999999; i++) { csTemp gg = new csTemp { MyProperty = 3213, MyProperty2 = 12312 }; } }