Questions tagged [enumeration]

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

Use for enumeration types.

1894 questions
16
votes
3 answers

Scala enumeration type fail in match/case

Enumerated values seem to fail in match/case expressions. This is what happens in a worksheet. object EnumType extends Enumeration { type EnumType = Value val a, b = Value } import EnumType._ val x: EnumType = b //> x…
RussAbbott
  • 2,660
  • 4
  • 24
  • 37
15
votes
2 answers

Possible multiple enumeration of IEnumerable?

why is that ? how can I fix it ?
Royi Namir
  • 144,742
  • 138
  • 468
  • 792
15
votes
3 answers

BitArray returns bits the wrong way around?

This code: BitArray bits = new BitArray(new byte[] { 7 }); foreach (bool bit in bits) { Console.WriteLine(bit ? 1 : 0); } Gives me the following output: 11100000 Shouldn't it be the other way around? Like this: 00000111 I am aware that there…
haiyyu
  • 2,194
  • 6
  • 22
  • 34
15
votes
3 answers

Enumeration value 'SHKShareTypeUndefined' not handled in switch

I get the warning Enumeration value 'SHKShareTypeUndefined' not handled in switch in the below code. I bolded the relevant line and pointer: + (NSArray *)favoriteSharersForType:(SHKShareType)type { NSArray *favoriteSharers =…
SimplyKiwi
  • 12,376
  • 22
  • 105
  • 191
15
votes
5 answers

A way to parse .NET enum string or int value attributed with 'Flags'

There is a nice way of figuring out the enumeration element using the following approach: // memberType is enum type if (Enum.IsDefined(memberType, valueString)) { return Enum.Parse(memberType, valueString); } else { try { var…
Schultz9999
  • 8,717
  • 8
  • 48
  • 87
15
votes
5 answers

What is the advantage of creating an enumerable object using to_enum in Ruby?

Why would you create a proxy reference to an object in Ruby, by using the to_enum method rather than just using the object directly? I cannot think of any practical use for this, trying to understand this concept & where someone might use it, but…
Jason
  • 22,645
  • 5
  • 29
  • 51
15
votes
3 answers

How to map custom enumerated integer ordinals with hibernate?

I have an enum class named Status as follows public enum Status { PENDING(0), SUCCESS(1), FAILED(-1); private int st; private Status(int st){ this.st = st; } } and from other class I try to map this status enum public void…
user1479203
  • 437
  • 1
  • 8
  • 16
15
votes
4 answers

C#: Is a SortedDictionary sorted when you enumerate over it?

A SorteDictionary is according to MSDN sorted on the key. Does that mean that you can be sure that it will be sorted when you enumerate it in a foreach? Or does it just mean that the SortedDictionary works that way internally to have better…
Svish
  • 152,914
  • 173
  • 462
  • 620
14
votes
8 answers

Enumerator Implementation: Use struct or class?

I noticed that List defines its enumerator as a struct, while ArrayList defines its enumerator as a class. What's the difference? If I am to write an enumerator for my class, which one would be preferable? EDIT: My requirements cannot be…
Hosam Aly
  • 41,555
  • 36
  • 141
  • 182
14
votes
3 answers

C# Converting set flags in a variable of type flag enumeration to an array of integers

I came up with this piece of code that converts the set flags in a variable of type Flag Enumeration and returns the set flags as integers. I'd like to know if this is the best approach. Example enumeration: [Flags] enum Status { None = 0x0, …
Cameri
  • 143
  • 1
  • 1
  • 6
14
votes
4 answers

multi-column factorize in pandas

The pandas factorize function assigns each unique value in a series to a sequential, 0-based index, and calculates which index each series entry belongs to. I'd like to accomplish the equivalent of pandas.factorize on multiple columns: import pandas…
ChrisB
  • 4,628
  • 7
  • 29
  • 41
13
votes
4 answers

ruby sort array of an array

I'm having a problem figuring out how I can sort an array of an array. Both arrays are straight forward and I'm sure it's quite simple, but I can't seem to figure it out. Here's the array: [["happy", 1], ["sad", 2], ["mad", 1], ["bad", 3], ["glad",…
ere
  • 1,739
  • 3
  • 19
  • 41
13
votes
3 answers

Looping through a list of Actions

I can't understand how to loop through an Action list. When I try it, I end up with the values being the same as the previous iteration. Here's the code (simplified example): string[] strings = { "abc", "def", "ghi" }; var actions = new…
demoncodemonkey
  • 11,730
  • 10
  • 61
  • 103
13
votes
6 answers

Get the representation value of an enumeration type in Ada

I need to get the numeric value asociated with a value of an enumerated type in Ada. Not the position in the enumeration, but the value assigned with the "for TYPE use" clause to every value. Does anyone know if it is possible?
user1240854
  • 143
  • 1
  • 1
  • 5
13
votes
6 answers

Enumerate through a subset of a Collection in C#?

Is there a good way to enumerate through only a subset of a Collection in C#? That is, I have a collection of a large number of objects (say, 1000), but I'd like to enumerate through only elements 250 - 340. Is there a good way to get an…
Paul Sonier
  • 38,903
  • 3
  • 77
  • 117