Skip to content

Instantly share code, notes, and snippets.

@Manuel-S
Created March 16, 2018 16:52
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Manuel-S/5fbaea145727fbd8311035ef1aa7f92b to your computer and use it in GitHub Desktop.
Save Manuel-S/5fbaea145727fbd8311035ef1aa7f92b to your computer and use it in GitHub Desktop.
A good way to save constant identifier strings in C#
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