Anonymous types in C# allow you to create objects with properties defined at compile-time without specifying a named class. They are often used for ad-hoc data structures.
Example:
var person = new { Name = "Mohan", Age = 30 };
Console.WriteLine($"Name: {person.Name}, Age: {person.Age}");
Var Type:
The 'var' keyword is used to implicitly declare variables, letting the compiler determine the data type based on the assigned value.
Example:
var number = 42;
Console.WriteLine($"Number is of type: {number.GetType()}");
Dynamic Type:
The 'dynamic' keyword allows you to create variables whose type is determined at runtime, providing flexibility but sacrificing compile-time type checking.
Example:
dynamic value = 10;
Console.WriteLine($"Dynamic value: {value}");
value = "Hello";
Console.WriteLine($"Dynamic value: {value}");
Tuple:
Tuples allow you to group multiple values of different types into a single data structure.
Example:
var personInfo = Tuple.Create("John", 30);
Console.WriteLine($"Name: {personInfo.Item1}, Age: {personInfo.Item2}");