enumeration

How can I create an enumeration for colors in window forms application?

SO Commmunity I have come across a 'problem' that I think must be quite common and wondered if anybody could help. I am building a simple windows form (using VB.NET) for a friend to use at work. His company has about 10 specific colors schemes (they have list of RGB values) that they use for the company logo, website etc. I want to fo...

Enumerating all strings meeting given restrictions

I'm looking for the name of the following class of problem, so that I can google for effective algorithms and more information. I have an alphabet with three characters {-1, 0, 1}. I need to effectively generate all strings of length 24 which are mostly {0} but have zero to eight {1,-1} characters distributed in certain patterns. (The...

DirectInput analogue joystick range

I use DirectInput to handle input devices, I enumerate devices and elements on each device. When using the analogue sticks on my game pad, they report values in the range 0-65535. Is this always the case for all types of absolute axis? If not: is there any way to find out the range of an DX8 input element's DIDEVICEOBJECTDATA::dwData (...

Fast way to enumerate all files including sub-folders

Does anyone know of a faster way to enumerate through a directory and sub-folders to gather all the files in the enumeration? This is what I have right now: Public Shared allFiles() As String allFiles = Directory.GetFiles(<ServerLocation>, "*.*", SearchOption.AllDirectories) Thanks! JFV EDIT: I am enumerating these files from a ser...

Converting Enumeration to Iterator

I have the following implicit conversion for java.util.Enumerations implicit def enumerationIterator[A](e : Enumeration[A]) : Iterator[A] = { new Iterator[A] { def hasNext = e.hasMoreElements def next = e.nextElement def remove = throw new UnsupportedOperationException() } } Unfortunately it doe...

.net enumeration first and last

is there a way in .NET (or some sort of standard extension methods) to ask questions of an enumeration? For example is the current item the first or last item in the enumeration: string s = ""; foreach (var person in PeopleListEnumerator) { if (PeopleListEnumerator.IsFirstItem) s += "["; s += person.ToString(); if (!PeopleLis...

Enumerating array which contains a dictionary produces unexpected output

My question is why does it output the last 4 lines in the log(see below)...those objects are part of the dictionary printed earlier in the log & should not be located at the end of the array? I am missing something fundamental here... thx NSDictionary *dictionary = [NSDictionary dictionaryWithObjectsAndKeys: [NSURL URLWithString: @"www...

How to count lines? : Objective-C

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) { range = [string lineRangeForRange:NSMakeRange(range.location, 0)]; range.lo...

IEnumerable , IEnumerator vs foreach, when to use what

Hi All, 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 example. Any suggestions and remarks are welcome. Thanks. ...

Use List<T>ForEach to add element to HashTable

I have a list of string values that I want add to a hashtable or other array that can be accessed by key/index but cannot implement it. I have this working how I want but its ugly List<string> valueList = new List<string>(); valueList.Add("1"); valueList.Add("2"); valueList.Add("3"); Hashtable p ...

What would be the smartest way of running permutational code sequences to run via enumerator?

I have the following enum ( pseudo code ) enum RunSequence : int { ABCD = 1 , BCDA = 2 , DABC = 3 , .... } You get the idea ... Now if each letter represents some 4 lines of code , what would be the smartest way of building the logic for running those 16 lines of code in the desired sequence according to the RunSequence passed ...

J2ME Get Specific Object from Vector

Currently I'm implementing a Persistant Storage Object for my Blackberry Application. It contains a Vector of Setting Objects. My current implemention to get specific settings value looks like this public String getSettingByName(String key) { String value = ""; for ( Enumeration e = _appSettings.elements(); e.hasMoreElements();) ...

When items change while being enumerated does it affects the enumeration?

Imagine that during a foreach(var item in enumerable) The enumerable items change. It will affect the current foreach? Example: var enumerable = new List<int>(); enumerable.Add(1); Parallel.ForEach<int>(enumerable, item => { enumerable.Add(item + 1); }); It will loop forever? ...

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 performance in various cases? ...

What are the different ways of handling 'Enumerations' in SQL server?

We currently define a list of constants (mostly these correspond to enumerations we have defined in the business layer) at the top of a stored procedure like so: DECLARE @COLOR_RED INT = 1 DECLARE @COLOR_GREEN INT = 2 DECLARE @COLOR_BLUE INT = 3 But these often get repeated for many stored procedures so there is a lot of duplication. ...

Scala enumeration and reflection

Hello all, After working in Java for a long time, I started to get interested in Scala. As a learning project, I am trying to duplicate a java library that stores and retrieves state objects from the database. For this, I would like to be able to just specify a state object like this: @PersistName("PERSON") case class Person extends ...

How to setup constants like this - Constants.Page.Title.MyCase - in C#?

Hi guys I am trying how figure how to setup like for instance Color.RGG.Black which equal to "#000000" I am trying to make it similar like that and implement into my Constants Class. How do I do this? Constants.Page.Title.MyCase equal to "My Case"; Thanks ...

Tree enumeration, n-depth and m-width

Hi all, I am trying to develop a java algorithm for the enumeration of n-depth and m-width trees: Each node can have at maximum 7 children. Nodes are of different type: a first kind of node can have children but can not be a leaf. The second can have no child (so it must be a leaf). The root is at depth 0 and the width is the maximum ...

Enumerating Outlook ContactItem properties

Hello, I'm trying to enumerate the properties of an Microsoft.Office.Interop.Outlook.ContactItem object (let's call it ci) with this code: System.Reflection.BindingFlags bf = System.Reflection.BindingFlags.Default; foreach (System.Reflection.PropertyInfo pi in ci.GetType().GetProperties(bf)) { Conso...

Enumeration hasMoreElements()

I have a JSP/HTML form where there are 2 elements.One is a select dropdown and another is a File upload box(input type="file").I use POST method and enctype as form-multipart.Now I am able to access both the dropdown list and file using MultipartRequest object.No problem in that. But when I don't upload any file and when I use a code in...