下面的代码块是一个使用nameof的简单例子。
class Program { static void Main(string[] args) { WriteLine(nameof(Student)); WriteLine(nameof(Student.Roll)); WriteLine(nameof(Student.Name)); WriteLine(nameof(Student.Address)); } } class Student { public int Roll { get; set; } public string Name { get; set; } public Address Address { get; set; } }