Explain Anonymous type in C#
Explain Anonymous type in C#
Anonymous types in C# are a way to create simple, lightweight objects without explicitly defining a class. They allow you to create objects on the fly, encapsulating a set of properties, without the need to define a separate class or struct.
Here are the key points about anonymous types in C#:
To create an anonymous type, you use the new keyword followed by curly braces {} and specify the properties inside. For example:
var person = new { Name = "John Doe", Age = 30 };
In this example, person is an anonymous type with two properties: Name and Age.
The property names of an anonymous type are inferred from the left-hand side of the assignment. In the previous example, Name and Age are the property names.
Đăng nhập để tham gia thảo luận cùng mọi người.
Chưa có bình luận nào
Hãy là người đầu tiên chia sẻ suy nghĩ của bạn.