Created
March 16, 2018 16:52
-
-
Save Manuel-S/5fbaea145727fbd8311035ef1aa7f92b to your computer and use it in GitHub Desktop.
A good way to save constant identifier strings in C#
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Runtime.CompilerServices; | |
public class Program | |
{ | |
public static readonly string IdString = CallerName(); | |
public static readonly string IdString2 = CallerName(); | |
public static string CallerName([CallerMemberName]string name = default) | |
=> name; | |
public static void Main() | |
{ | |
Console.WriteLine(IdString + IdString2); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment