tagged [enumeration]

Is there a predefined enumeration for Month in the .NET library?

Is there a predefined enumeration for Month in the .NET library? I'm looking to see if there is an official enumeration for months in the .net framework. It seems possible to me that there is one, bec...

1 May at 00:11

How to handle an "infinite" IEnumerable?

How to handle an "infinite" IEnumerable? A trivial example of an "infinite" IEnumerable would be I know, that and both work fine

Looping through a list of Actions

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...

5 Mar at 15:33

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

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}, {...

Entity Framework enumerating SqlQuery result

Entity Framework enumerating SqlQuery result I have strange error while I am trying to view results of SqlQuery: So when debugger is at last line and when I try to expand Re

2 Apr at 10:18

WPF How to bind an enum with Description to a ComboBox

WPF How to bind an enum with Description to a ComboBox How can I bind an `enum` with `Description` (`DescriptionAttribute`) to a `ComboBox`? I got an `enum`: I tried this: ```

Why is the enumeration value from a multi dimensional array not equal to itself?

Why is the enumeration value from a multi dimensional array not equal to itself? Consider: How can this be explained?

Changing objects value in foreach loop?

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, But for object of class i am not ab...

30 Dec at 12:54

Enumerations on PHP

Enumerations on PHP I know that PHP doesn't yet have native Enumerations. But I have become accustomed to them from the Java world. I would love to use enums as a way to give predefined values which I...

16 Feb at 07:17

What is the best way to modify a list in a 'foreach' loop?

What is the best way to modify a list in a 'foreach' loop? A new feature in C# / .NET 4.0 is that you can change your enumerable in a `foreach` without getting the exception. See Paul Jackson's blog e...

8 Sep at 14:10

Distinction between iterator and enumerator

Distinction between iterator and enumerator An interview question for a .NET 3.5 job is "What is the difference between an iterator and an enumerator"? This is a core distinction to make, what with LI...

The foreach identifier and closures

The foreach identifier and closures In the two following snippets, is the first one safe or must you do the second one? By safe I mean is each thread guaranteed to call the method on the Foo from the ...

17 Dec at 18:45

Why and how (internally) does Enum.IsDefined search for both name and value?

Why and how (internally) does Enum.IsDefined search for both name and value? Lets say we have defined `Planets` enum: I was using `Enum.IsDefined` method for finding whether string exists in enum or n...

10 May at 11:27

What is the tilde (~) in the enum definition?

What is the tilde (~) in the enum definition? I'm always surprised that even after using C# for all this time now, I still manage to find things I didn't know about... I've tried searching the interne...

Search for a string in Enum and return the Enum

Search for a string in Enum and return the Enum I have an enumeration: and I have a string: I want to be able to return: from: --- So far i have: ``` public MyColours G

19 Mar at 14:29

working pattern of yield return

working pattern of yield return When i have a code block can i inter

20 Oct at 20:14

Why am I getting "Collection was modified; enumeration operation may not execute" when not modifying the enumerated collection?

Why am I getting "Collection was modified; enumeration operation may not execute" when not modifying the enumerated collection? I have two collections of strings: CollectionA is a StringCollection pro...

7 May at 20:31

Strange thing about .NET 4.0 filesystem enumeration functionality

Strange thing about .NET 4.0 filesystem enumeration functionality I just read a page of ["Whats new .NET Framework 4.0"](http://msdn.microsoft.com/en-us/library/dd997370.aspx). I have trouble understa...

2 Jun at 09:29

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

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.I...

26 Apr at 20:57

When and how should I use enumeration classes rather than enums?

When and how should I use enumeration classes rather than enums? A developer at work recently started using a class pattern instead of enums in places where enums would usually fit. Instead, he uses s...

Strange "Collection was modified after the enumerator was instantiated" exception

Strange "Collection was modified after the enumerator was instantiated" exception Perhaps someone can point me in the correct direction, because I'm completely stumped on this. I have a function that ...

26 May at 12:11

Discovering the class where a property is first published with multiple levels of inheritance

Discovering the class where a property is first published with multiple levels of inheritance Using the Typinfo unit, it is easy to enumerate properties as seen in the following snippet: ``` procedure...

2 Aug at 16:52

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

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 (j...

List all bit names from a flag Enum

List all bit names from a flag Enum I'm trying to make a helper method for listing the names of all bits set in an Enum value (for logging purposes). I want have a method that would return the list of...

11 Apr at 18:57

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

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 ...

8 Jul at 21:53