nameof
will return name of the variable, type(class, interface..), fucntion/method name
reference:
https://docs.microsoft.com/en-us/dotnet/csharp/language-reference/operators/nameof
code snippet:
>)); // output: Listwill return name of the variable, type(class, interface..), fucntion/method name
reference:
https://docs.microsoft.com/en-us/dotnet/csharp/language-reference/operators/nameof
code snippet:
Console.WriteLine(nameof(System.Collections.Generic)); // output: Generic
Console.WriteLine(nameof(Listtring
Console.WriteLine(nameof(List<string>.Count)); // output: Count
Console.WriteLine(nameof(List<string>.Add)); // output: Add
var numbers = new List<string> { "ab", "cd", "ef" };
Console.WriteLine(nameof(numbers)); // output: numbers
Console.WriteLine(nameof(numbers.Count)); // output: Count
Console.WriteLine(nameof(numbers.Add)); // output: Add
No comments:
Post a Comment