你可以在你的类上提供一个 static 或 const 成员:
class PickyClass {
public static readonly string[] RequiredKeys = new[] {"length", "width"};
/// <summary>
/// Please note that you must include at least RequiredKeys in values
/// </summary>
public void Setup(Dictionary<string,string> values)
{
...
}
}
(编辑)还是按名称可寻址它们很重要?在这种情况下,如何:
class PickyClass {
public class RequiredKeys
{
public const string Length = "length";
public const string Width = "width";
}
/// <summary>
/// Please note that you must include every const in RequiredKeys in values
/// </summary>
public void Setup(Dictionary<string,string> values)
{
...
}
}