This code demonstrates three fundamental C# concepts: Structs, Classes, and Enums. The key focus is understanding the difference between value types (structs) and reference types (classes).
public enum Branch
{
Mechacnical = 77, // Note: typo in "Mechanical"
Chemical= 44,
IT = 4,
CS=7,
Civil, // Will be 8 (CS + 1)
ENTC // Will be 9 (Civil + 1)
}
Branch branch = Branch.Civil;
Console.WriteLine(branch); // Output: Civil
Console.WriteLine(Convert.ToInt32(branch)); // Output: 8
Mechacnical = 77
)Civil
= 8 (CS value 7 + 1)ENTC
= 9 (Civil value 8 + 1)The commented code in the first region demonstrates a crucial concept:
Person person1 = new Person();
person1.No = 10;
person1.Name = "Sachin";
Person person2 = person1; // This line behaves DIFFERENTLY for struct vs class
person2.Name = "Amit";
Console.WriteLine(person1.Name); // What will this print?
Console.WriteLine(person2.Name); // What will this print?