在类中使用const和Func有何优劣之处或区别?
public sealed class Constants {
private Constants() {}
public const string SOME_STRING = "Some String";
public static Func<string> SomeString = () => "Some String";
}
Debug.WriteLine(Constants.SOME_STRING);
Debug.WriteLine(Constants.SomeString());
Func
用作const
的替代品。我认为使用只读属性是一个有效的替代方案。 - Uwe Keimreadonly
值。 - Jeff Mercadopublic static readonly
而不是Func。 - Justin Pihony