18
1
//Example by TutorialsTeacher.com
2
//Learn about anonymous type at https://www.tutorialsteacher.com/csharp/csharp-anonymous-type
3
using System;
4
5
public class Program
6
{
7
public static void Main()
8
{
9
var student = new { Id = 1, FirstName = "James", LastName = "Bond" };
10
11
Console.WriteLine(student.Id); //output: 1
12
Console.WriteLine(student.FirstName); //output: James
13
Console.WriteLine(student.LastName); //output: Bond
14
//the following will give compile-time error
15
//student.Id = 2; //error
16
//student.FirstName = "Steve"; //error
17
}
18
}
Cached Result
1
James
Bond
James
Bond