Questions tagged [enumeration]

The process of enumerating values, for example from some collection.

Use for enumeration types.

1894 questions
39
votes
4 answers

enum implementation inside interface - Java

I have a question about putting a Java enum in the interface. To make it clearer, please see the following code: public interface Thing{ public enum Number{ one(1), two(2), three(3); private int value; private Number(int…
Joey
  • 2,732
  • 11
  • 43
  • 63
37
votes
5 answers

Return Type of Java Generic Methods

I wonder why generic methods which return nothing void are (or can be) declared this way: public static void printArray( E[] inputArray ) { // Display array elements for ( E element : inputArray ){ …
user975343
36
votes
5 answers

How to stop enumerateObjectsUsingBlock Swift

How do I stop a block enumeration? myArray.enumerateObjectsUsingBlock( { object, index, stop in //how do I stop the enumeration in here?? }) I know in obj-c you do this: [myArray enumerateObjectsUsingBlock:^(id *myObject,…
random
  • 8,568
  • 12
  • 50
  • 85
35
votes
12 answers

Why do people use enums in C++ as constants while they can use const?

Why do people use enums in C++ as constants when they can use const?
Loai Abdelhalim
  • 1,901
  • 4
  • 24
  • 28
35
votes
3 answers

Changing objects value in foreach loop?

In one place i am using the list of string in that case the i am able to change the value of the string as code given below, foreach(string item in itemlist.ToList()) { item = someValue; //I am able to do this } But for object of class i am…
user2553512
35
votes
7 answers

case class copy 'method' with superclass

I want to do something like this: sealed abstract class Base(val myparam:String) case class Foo(override val myparam:String) extends Base(myparam) case class Bar(override val myparam:String) extends Base(myparam) def getIt( a:Base ) =…
nairbv
  • 4,045
  • 1
  • 24
  • 26
33
votes
4 answers

Dictionary enumeration in C#

How do I enumerate a dictionary? Suppose I use foreach() for dictionay enumeration. I can't update a key/value pair inside foreach(). So I want some other method.
Ravi
  • 1,263
  • 6
  • 17
  • 23
32
votes
7 answers

How to get Get a C# Enumeration in Javascript

I have an enum in my C# code and I want to get the same enum in javascript. Is there any way to do this without hardcoding?
Jishnu A P
  • 14,202
  • 8
  • 40
  • 50
32
votes
7 answers

C++ - enum vs. const vs. #define

At the end of the article here: http://www.learncpp.com/cpp-tutorial/45-enumerated-types/, it mentions the following: Finally, as with constant variables, enumerated types show up in the debugger, making them more useful than #defined values in this…
Simplicity
  • 47,404
  • 98
  • 256
  • 385
32
votes
4 answers

Overriding Scala Enumeration Value

As far as I can tell, Scala has definitions for the Enumeration Value class for Value(Int), Value(String), and Value(Int, String). Does anyone know of an example for creating a new Value subclass to support a different constructor? For example, If I…
Ralph
  • 31,584
  • 38
  • 145
  • 282
31
votes
5 answers

What is the best way to convert an IEnumerator to a generic IEnumerator?

I am writing a custom ConfigurationElementCollection for a custom ConfigurationHandler in C#.NET 3.5 and I am wanting to expose the IEnumerator as a generic IEnumerator. What would be the best way to achieve this? I am currently using the…
zonkflut
  • 2,929
  • 3
  • 22
  • 25
31
votes
9 answers

Is there a way to iterate through all enum values?

Possible Duplicate: C#: How to enumerate an enum? The subject says all. I want to use that to add the values of an enum in a combobox. Thanks vIceBerg
vIceBerg
  • 4,197
  • 5
  • 40
  • 53
30
votes
11 answers

Can Swift enums have multiple raw values?

I want to associate two raw values to an enum instance (imagine an enum representing error types, I want Error.Teapot to have an Int type property code with value 418, and a String property set to I'm a teapot.) Note the difference between raw…
Robert Atkins
  • 23,528
  • 15
  • 68
  • 97
29
votes
11 answers

IEnumerable as return type

Is there a problem with using IEnumerable as a return type? FxCop complains about returning List (it advises returning Collection instead). Well, I've always been guided by a rule "accept the least you can, but return the maximum." From…
Valentin V
  • 24,971
  • 33
  • 103
  • 152
29
votes
9 answers

Why can't we change values of a dictionary while enumerating its keys?

class Program { static void Main(string[] args) { var dictionary = new Dictionary() { {"1", 1}, {"2", 2}, {"3", 3} }; foreach (var s in dictionary.Keys) { //…
Vitaliy
  • 8,044
  • 7
  • 38
  • 66