1.实现代码
using System;namespace NameofUsage{ ////// C# nameof用法 /// internal class Program { private static void Main() { Console.Title = "C# nameof用法"; Person p = new Person(); Console.WriteLine(nameof(p)); Console.WriteLine(nameof(p.Name)); Console.WriteLine(nameof(Person.CreateDateTime)); Console.ReadKey(); } } public class Person { public long Id { get; set; } public string Name { get; set; } public DateTime CreateDateTime { get; set; } }}
2.运行效果