Click here to Skip to main content
15,890,506 members
Home / Discussions / C#
   

C#

 
Questionalways black screen Pin
josephdalebert2-Nov-13 23:33
josephdalebert2-Nov-13 23:33 
AnswerRe: always black screen Pin
Richard Andrew x643-Nov-13 13:20
professionalRichard Andrew x643-Nov-13 13:20 
QuestionC# Generic Dictionary ordered by Value: is it really ordered ? Pin
BillWoodruff2-Nov-13 8:05
professionalBillWoodruff2-Nov-13 8:05 
AnswerRe: C# Generic Dictionary ordered by Value: is it really ordered ? Pin
harold aptroot2-Nov-13 8:23
harold aptroot2-Nov-13 8:23 
GeneralRe: C# Generic Dictionary ordered by Value: is it really ordered ? Pin
BillWoodruff2-Nov-13 18:43
professionalBillWoodruff2-Nov-13 18:43 
AnswerRe: C# Generic Dictionary ordered by Value: is it really ordered ? Pin
TnTinMn2-Nov-13 17:28
TnTinMn2-Nov-13 17:28 
GeneralRe: C# Generic Dictionary ordered by Value: is it really ordered ? Pin
BillWoodruff2-Nov-13 18:48
professionalBillWoodruff2-Nov-13 18:48 
GeneralRe: C# Generic Dictionary ordered by Value: is it really ordered ? Pin
TnTinMn3-Nov-13 10:50
TnTinMn3-Nov-13 10:50 
Quote:
I assume that all Linq methods are static methods that require an IEnumerable to work. Perhaps I am not fully educated ?
As far as I know, you are correct and I do hope that I did not imply otherwise. Sniff | :^)
Quote:
The distinction between calling the "raw" method, and calling the method "off" IEnumerable, as you show, is not clear to me, but I will study your post carefully.

All that I was trying to convey with that was that a new IEnumerable<KeyValuepair<Int32, Int32>>is returned by the query. If you run GetType.Fullname against it, you will get something like this:
System.Linq.OrderedEnumerable`2[[System.Collections.Generic.KeyValuePair`2[[System.Int32, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089],[System.Int32, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089]], mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089],[System.Int32, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089]]
This returned class is created by enumerating the source (the Dictionary).

I apologize if the following is a bit basic and long winded, but I cannot think of another way to make my point. I do not intend to insult your intellegence.

It is easy to forget how a collection is enumerated especially since the "foreach statement" replaces all the grunt work for us.
Borrowing from http://msdn.microsoft.com/en-us/library/system.collections.ienumerator.aspx?cs-save-lang=1&cs-lang=csharp#code-snippet-2[^].
C#
foreach (Person p in peopleList)
    Console.WriteLine(p.firstName + " " + p.lastName);

Doing it the long winded way:
C#
IEnumerator en = peopleList.GetEnumerator();
Person p;
while (en.MoveNext())
{
    p = (Person)en.Current;
    Console.WriteLine(p.firstName + " " + p.lastName);
}
Each MoveNext call checks if any items remain in the collection and method Current returns the next object in the sequence.

With the classes defined as:
C#
public class People : IEnumerable
{
    private Person[] _people;
    public People(Person[] pArray)
    {
        _people = new Person[pArray.Length];

        for (int i = 0; i < pArray.Length; i++)
        {
            _people[i] = pArray[i];
        }
    }

    IEnumerator IEnumerable.GetEnumerator()
    {
        return (IEnumerator)GetEnumerator();
    }

    public PeopleEnum GetEnumerator()
    {
        return new PeopleEnum(_people);
    }
}

public class PeopleEnum : IEnumerator
{
    public Person[] _people;

    // Enumerators are positioned before the first element 
    // until the first MoveNext() call. 
    int position = -1;

    public PeopleEnum(Person[] list)
    {
        _people = list;
    }

    public bool MoveNext()
    {
        position++;
        return (position < _people.Length);
    }

    public void Reset()
    {
        position = -1;
    }

    object IEnumerator.Current
    {
        get
        {
            try
            {
                return _people[position];
            }
            catch (IndexOutOfRangeException)
            {
                throw new InvalidOperationException();
            }
        }
    }

}
The point of this all was to show that an IEnumerable is nothing more than a class that holds a collection of objects (Array or whatever) that provides a mechanism to retrieve those objects in a sequence order defined by the IEnumerator class. In the case of OrderedEnumerable this return order is supplied by a array that contains the backing array indices sorted as stipulated by the supplied IComparer.

Now in the case of Dictionary, I showed in my previous post the MoveNext method that indicates that the hash value is only used determine where or not particular backing array entry is holding a value. The hash value only figures in when trying to retrieve a value by key; a procedure that play no part in enumerating the dictionary.

I hope this helps clear up my ramblings from last night without making it any worse. Poke tongue | ;-P
AnswerRe: C# Generic Dictionary ordered by Value: is it really ordered ? Pin
jschell4-Nov-13 8:05
jschell4-Nov-13 8:05 
AnswerRe: C# Generic Dictionary ordered by Value: is it really ordered ? Pin
Keith Barrow5-Nov-13 2:22
professionalKeith Barrow5-Nov-13 2:22 
QuestionBurning open file to CD/DVD Pin
Member 103095672-Nov-13 1:34
Member 103095672-Nov-13 1:34 
AnswerRe: Burning open file to CD/DVD Pin
Dave Kreskowiak2-Nov-13 9:20
mveDave Kreskowiak2-Nov-13 9:20 
GeneralRe: Burning open file to CD/DVD Pin
Member 103095672-Nov-13 9:45
Member 103095672-Nov-13 9:45 
AnswerRe: Burning open file to CD/DVD Pin
TnTinMn3-Nov-13 11:58
TnTinMn3-Nov-13 11:58 
QuestionComparing a name inputted against a database of names Pin
JacksonVF1-Nov-13 22:56
JacksonVF1-Nov-13 22:56 
AnswerRe: Comparing a name inputted against a database of names Pin
Mycroft Holmes2-Nov-13 1:21
professionalMycroft Holmes2-Nov-13 1:21 
GeneralRe: Comparing a name inputted against a database of names Pin
JacksonVF2-Nov-13 2:45
JacksonVF2-Nov-13 2:45 
AnswerRe: Comparing a name inputted against a database of names Pin
jschell2-Nov-13 6:49
jschell2-Nov-13 6:49 
AnswerRe: Comparing a name inputted against a database of names Pin
PIEBALDconsult4-Nov-13 4:11
mvePIEBALDconsult4-Nov-13 4:11 
Questionsingle chat TCP, Console C# Pin
Member 103468781-Nov-13 19:01
Member 103468781-Nov-13 19:01 
AnswerRe: single chat TCP, Console C# Pin
Mycroft Holmes1-Nov-13 22:10
professionalMycroft Holmes1-Nov-13 22:10 
GeneralRe: single chat TCP, Console C# Pin
Dave Kreskowiak2-Nov-13 9:12
mveDave Kreskowiak2-Nov-13 9:12 
QuestionPage_init with variable Pin
vkEE1-Nov-13 8:14
vkEE1-Nov-13 8:14 
SuggestionRe: Page_init with variable Pin
Matt T Heffron1-Nov-13 13:25
professionalMatt T Heffron1-Nov-13 13:25 
QuestionI have a problem regarding my project. thanks for answering this :)) Pin
josephdalebert1-Nov-13 6:50
josephdalebert1-Nov-13 6:50 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.