0

我有这样的代码:

var types = Get("07").ToList();

这是针对城市类型的

var types = Get("08").ToList();

这是街道类型

有没有办法可以在我写的地方使用类似枚举的东西:

var types = Get(TYPE.City).ToList();
var types = Get(TYPE.Street).ToList();  

更新:

我也很高兴听到任何更好的选择。谢谢

4

4 回答 4

3

如果您真的在使用enum,请执行以下操作:

public enum TYPE {
    City = 7,
    Street = 8
};

var types = Get(TYPE.City.ToString("00")).ToList();
于 2012-09-14T10:42:05.967 回答
2

enum您可以创建一个class.

public static class TYPE
{
    public static readonly string City = "07";
    public static readonly string Street = "08";
}

// Usage:
var types = Get(TYPE.City).ToList(); // this evaluates to .Get("07")
于 2012-09-14T10:43:51.740 回答
1

你可以定义static

public static class TYPE
{
    public static string City = "07";
    public static string Street = "08";
}
于 2012-09-14T10:42:07.750 回答
1

您可以使用包含这些值的常量或静态只读字段创建类。

例如:

static class TYPE
{
    public const string City = "07";
    public const string Street = "08";
}
于 2012-09-14T10:47:25.083 回答