This question already has an answer here: How do I iterate over an enum? 26 answers Can you loop through all enum values? [duplicate] 8 answers 尝试foreach(var base in Enum.GetValues(typeof(Base)).Cast<Base>()) { doc = vircurex.get_lowest_ask(base) }
这个问题在这里已经有了答案: 我如何迭代枚举? 26个答案 你可以遍历所有的枚举值? [复制] 8个答案 尝试foreach(var base in Enum.GetValues(typeof(Base)).Cast<Base>()) { doc = vircurex.get_lowest_ask(base) }
Possible Duplicate: How do I enumerate an enum? Suppose there is an enum public enum Numbers {one, two, three }; What do I have to write instead of the three dots in the following code in order to get output "one", "two", "three": foreach (Numbers n in ...) { Console.WriteLine (n.ToString ()); } Of course, I would like to do it in a way such that modifying
可能重复: 我如何列举一个枚举? 假设有一个枚举 public enum Numbers {one, two, three }; 为了获得输出“一”,“二”,“三”,我必须在下面的代码中写下三个点而不是三个点: foreach (Numbers n in ...) { Console.WriteLine (n.ToString ()); } 当然,我想这样做是为了修改枚举定义并不需要修改foreach()中的代码。 你可以使用: foreach (Numbers n in Enum.GetValues(typeof(Numbers))) { Console.WriteLin
This question already has an answer here: How do I iterate over an enum? 26 answers Can you loop through all enum values? [duplicate] 8 answers
这个问题在这里已经有了答案: 我如何迭代枚举? 26个答案 你可以遍历所有的枚举值? [复制] 8个答案
Possible Duplicate: C#: How to enumerate an enum? Hi all I want to know that suppose I define a enum like enum color { red=4; blue=5; gray=6; green=8; } so can we print value of constant with the help of for loop, i means can we control it by loop; another question can we integrate it with dropdown list like as array. i means when we declare a element in side array suppose
可能重复: C#:如何枚举枚举? 大家好我想知道,假设我定义一个枚举类似 enum color { red=4; blue=5; gray=6; green=8; } 所以我们可以在for循环的帮助下打印常量的值,我的意思是我们可以通过循环来控制它; 另一个问题是我们可以将它与像下拉列表一样整合到数组中。 我意味着当我们在边数组中声明一个元素时,假设我编写了相同的颜色元素,并且我们可以在asp.net中使用列表或下拉列表(简单的文字绑
Possible Duplicate: How to enumerate an enum? So I have a bit of code like this: enum Decision { DecisionA, DecisionB, ... } public void DoStuff(Decision d) { switch(d) { case Decision.DecisionA: .... ... } } Basically DoStuff , will do the same thing no matter what the decision, but the decision is used to make what it does more optimal(faster or whatever). Now,
可能重复: 如何枚举枚举? 所以我有一些这样的代码: enum Decision { DecisionA, DecisionB, ... } public void DoStuff(Decision d) { switch(d) { case Decision.DecisionA: .... ... } } 基本上DoStuff无论做什么决定都会做同样的事情,但决定是用来做出更优化的(更快或者其他)。 现在,我想为DoStuff实施单元测试。 通过拥有像new Decision[]{DecisionA, DecisionB, ...};这样的数组
Possible Duplicate: How to enumerate an enum? Suppose that i have an enumeration like that: public enum Cars { Audi = 0, BMW, Opel, Renault, Fiat, Citroen, AlfaRomeo, } Do i have a chance to iterate between Opel and Citroen? I want to give these values as parameters of a method. This will work: for(Cars car=Cars.Opel; car<=Cars.Citroen; car++) { Console.
可能重复: 如何枚举枚举? 假设我有这样一个枚举: public enum Cars { Audi = 0, BMW, Opel, Renault, Fiat, Citroen, AlfaRomeo, } 我有机会在欧宝和雪铁龙之间进行迭代吗? 我想给这些值作为方法的参数。 这将工作: for(Cars car=Cars.Opel; car<=Cars.Citroen; car++) { Console.WriteLine(car); } 但您必须确保起始值小于最终值。 编辑 如果您没有对开始和结束进行硬编
This question already has an answer here: How do I iterate over an enum? 26 answers Enum类具有您正在寻找的方法。 foreach(int i in Enum.GetValues(typeof(stuff))) { String name = Enum.GetName(typeof(stuff), i); NewObject thing = new NewObject { Name = name, Number = i }; } 你可以使用LINQ(几乎总是): List<NewObject> stuff = Enum.GetValues(typeof(stuffEnum
这个问题在这里已经有了答案: 我如何迭代枚举? 26个答案 Enum类具有您正在寻找的方法。 foreach(int i in Enum.GetValues(typeof(stuff))) { String name = Enum.GetName(typeof(stuff), i); NewObject thing = new NewObject { Name = name, Number = i }; } 你可以使用LINQ(几乎总是): List<NewObject> stuff = Enum.GetValues(typeof(stuffEnum)).Cast<stuffEnum>()
Possible Duplicate: C#: How to enumerate an enum? Hi All, I have an Enum public enum AttributeType { TextField = 1, TextArea = 2, Date = 4, Boolean = 8 } I want to foreach this enum and make an object array of it in this format object data = new object[] { // new object[] { 1,"TextField"} new object[] { enumValue, enumText} }; Well, this w
可能重复: C#:如何枚举枚举? 大家好, 我有一个枚举 public enum AttributeType { TextField = 1, TextArea = 2, Date = 4, Boolean = 8 } 我想要foreach这个枚举并以这种格式创建一个对象数组 object data = new object[] { // new object[] { 1,"TextField"} new object[] { enumValue, enumText} }; 那么,这将做到这一点(假设.NET 3.5): var allValues =
Possible Duplicate: How do I enumerate an enum? Say I have an enum type MyEnum. Is there a way in C# to get a list of all possible values for an enum of type MyEnum? An instance of the enum can have any assignable to the underlying type (ie, int.MinValue through int.MaxValue for any regular enum). You can get a list of the named values by calling Enum.GetNames and Enum.GetValues . Enum.
可能重复: 我如何列举一个枚举? 假设我有一个枚举类型MyEnum。 有没有办法在C#中获取MyEnum类型枚举的所有可能值的列表? 枚举的实例可以有任何可分配给基础类型的值(例如,对于任何常规枚举, int.MinValue到int.MaxValue )。 您可以通过调用Enum.GetNames和Enum.GetValues来获取指定值的列表。 Enum.GetValues Enum.GetValues(typeof(SomeEnum)); 将返回一个包含所有值的数组。 我不知道这是否有助于你。
Possible Duplicate: How do I enumerate an enum? I don't know if it is possible to do what I want to do, but I think why not. I have example enum: public enum Animals { Cat, Dog, ... } What I want to do is to iterate on this enum. I want it work like that: foreach( var type in Animals ) { Console.WriteLine( type.toString() ); } and the output will be: Cat Dog Is
可能重复: 我如何列举一个枚举? 我不知道是否可以做我想做的事,但我想为什么不。 我有一个例子枚举: public enum Animals { Cat, Dog, ... } 我想要做的是迭代这个枚举。 我希望它能像那样工作: foreach( var type in Animals ) { Console.WriteLine( type.toString() ); } 并且输出将是: Cat Dog 可能吗? 我不想把每个项都放到一个数组中,然后迭代,我想直接在这个枚举上迭代。 编辑