Questions tagged [enumeration]

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

Use for enumeration types.

1894 questions
28
votes
3 answers

How do I convert an integer to an enumerated type?

I know how to convert an enumerated type to an integer. type TMyType = (mtFirst, mtSecond, mtThird); var ordValue:integer; enumValue:TMyType; ... ordValue:= Ord(mtSecond); // result is 1 But how do I do the inverse operation and convert an…
lyborko
  • 2,571
  • 3
  • 26
  • 54
28
votes
6 answers

Populate an enum with values from database

I have a table which maps String->Integer. Rather than create an enum statically, I want to populate the enum with values from a database. Is this possible ? So, rather than delcaring this statically: public enum Size { SMALL(0), MEDIUM(1),…
Jacques René Mesrine
  • 46,127
  • 27
  • 66
  • 104
28
votes
5 answers

How to handle an "infinite" IEnumerable?

A trivial example of an "infinite" IEnumerable would be IEnumerable Numbers() { int i=0; while(true) { yield return unchecked(i++); } } I know, that foreach(int i in Numbers().Take(10)) { Console.WriteLine(i); } and var q =…
Danvil
  • 22,240
  • 19
  • 65
  • 88
28
votes
3 answers

How to count the number of lines in an Objective-C string (NSString)?

I want to count the lines in an NSString in Objective-C. NSInteger lineNum = 0; NSString *string = @"abcde\nfghijk\nlmnopq\nrstu"; NSInteger length = [string length]; NSRange range = NSMakeRange(0, length); while (range.location < length)…
freddiefujiwara
  • 57,041
  • 28
  • 76
  • 106
27
votes
2 answers

Bug with For Each enumeration on x64 Custom Classes

I have found a bug in VBA a few months ago and was unable to find a decent workaround. The bug is really annoying as it kind of restricts a nice language feature. When using a Custom Collection Class it is quite common to want to have an enumerator…
Cristian Buse
  • 4,020
  • 1
  • 13
  • 34
27
votes
3 answers

Objective C — What is the fastest and most efficient way to enumerate an array?

Edit I read through some articles on blocks and fast enumeration and GCD and the like. @Bbum, who's written many articles on the subject of GCD and blocks, says that the block enumeration methods are always as fast or faster than the fast…
27
votes
5 answers

Enumerate over a sequence in Clojure?

In Python I can do this: animals = ['dog', 'cat', 'bird'] for i, animal in enumerate(animals): print i, animal Which outputs: 0 dog 1 cat 2 bird How would I accomplish the same thing in Clojure? I considered using a list comprehension like…
davidscolgan
  • 7,508
  • 9
  • 59
  • 78
27
votes
4 answers

How solve compiler enum redeclaration conflict

Consider the following C++ enumerations: enum Identity { UNKNOWN = 1, CHECKED = 2, UNCHECKED = 3 }; enum Status { UNKNOWN = 0, PENDING = 1, APPROVED = 2, UNAPPROVED = 3 }; The Compiler conflicted the both…
Daniel Santos
  • 14,328
  • 21
  • 91
  • 174
27
votes
1 answer

Passing enum parameter to a case class does not work

Can someone tell me why this does not work? case class XY(enum: MyEnum) object MyEnum extends Enumeration { val OP1, OP2 = Value } Error: not found: type MyEnum
user21845
  • 293
  • 3
  • 4
26
votes
3 answers

IEnumerable , IEnumerator vs foreach, when to use what

I was going through IEnumerable and IEnumerator , but could not get one point clearly..if we have foreach, then why do we need this two interfaces? Is there any scenario where we have to use interfaces.If yes, then can somebody explain with an…
Wondering
  • 4,950
  • 22
  • 71
  • 90
25
votes
1 answer

ARC Strong property Enumeration Error

I have the following code and am getting this error before compiling: Fast Enumeration Variables can't be modified in ARC by default, declare the variable _strong to allow this for (NSString *name in array){ @try { …
Eric
  • 4,063
  • 2
  • 27
  • 49
25
votes
4 answers

How to convert Enumeration to Seq/List in scala?

I'm writing a servlet, and need to get all parameters from the request. I found request.getParameterNames returns a java.util.Enumeration, so I have to write code as: val names = request.getParameterNames while(names.hasMoreElements) { val name…
Freewind
  • 193,756
  • 157
  • 432
  • 708
24
votes
5 answers

What is thread safe (C#) ? (Strings, arrays, ... ?)

I'm quite new to C# so please bear with me. I'm a bit confused with the thread safety. When is something thread safe and when something isn't? Is reading (just reading from something that was initialized before) from a field always thread safe?…
Ben
  • 2,435
  • 6
  • 43
  • 57
24
votes
3 answers

Entity Framework 6 Code First - Required Enum data type not working

I am generating a database table using an required enum field. However, when feeding the table, it is possible to omit to feed the enum field: EF will not throw any error message but will feed the field with 0 value. Can you help me understanding…
tit
  • 599
  • 3
  • 6
  • 25
24
votes
3 answers

Get to get all child scopes in Angularjs given the parent scope

I would like to know how to get a list of all child scopes given a parent scope. All I can find from the properties of the scope are $$childHead, $$childTail, $$nextSibling and $$prevSibling. The approach I'm using now is to get the childHead from…
ritcoder
  • 3,274
  • 10
  • 42
  • 62