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

C#

 
AnswerRe: List problem ! Pin
Paulo Augusto Kunzel4-Nov-13 3:02
professionalPaulo Augusto Kunzel4-Nov-13 3:02 
AnswerRe: List problem ! Pin
Pete O'Hanlon4-Nov-13 3:24
mvePete O'Hanlon4-Nov-13 3:24 
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 
I do not see an issue with you using LINQ OrderedBy to get a sorted copy of a Dictionary.

The OrderedBy method returns:
Type: System.Linq.IOrderedEnumerable(Of TSource)
An IOrderedEnumerable(Of TElement) whose elements are sorted according to a key.
In the case of a Dictionary, TElement is a KeyValuePair. This is more apparent when calling the static Enumerable.OrderBy method.
C#
System.Linq.IOrderedEnumerable<KeyValuePair<Int32, Int32>> ioe = System.Linq.Enumerable.OrderBy<KeyValuePair<Int32,Int32>, Int32>
    (randomDictionary, (KeyValuePair<Int32, Int32> x) => x.Key);
Bill said their argument is:
Given that a .NET Dictionary is implemented with the use of Hashes for fast look-up, those who believe it cannot be ordered describe that, and the statements by Microsoft about "no guarantee" of a specific order, as the reasons sorting is not possible
To this I say crawl into Reflector and see how that nasty hash is used in the Enumerator. All it is used for there is as way to tell if the Dictionary's "entries" array at the current index holds a value.
C#
public bool MoveNext()
{
    if (this.version != this.dictionary.version)
    {
        ThrowHelper.ThrowInvalidOperationException(ExceptionResource.InvalidOperation_EnumFailedVersion);
    }
    while (this.index < this.dictionary.count)
    {
        if (this.dictionary.entries[this.index].hashCode >= 0)
        {
            this.current = new KeyValuePair<TKey, TValue>(this.dictionary.entries[this.index].key, this.dictionary.entries[this.index].value);
            this.index++;
            return true;
        }
        this.index++;
    }
    this.index = this.dictionary.count + 1;
    this.current = new KeyValuePair<TKey, TValue>();
    return false;
}
About this statement from the documentation being a concern:
For purposes of enumeration, each item in the dictionary is treated as a KeyValuePair(Of TKey, TValue) structure representing a value and its key. The order in which the items are returned is undefined.
To this, I say so what, if the order of returned KVP's is undefined. It doesn't matter what the returned order is when copying them to another class that will present them in sorted order.

Well, so much for my analysis. I could be full of it on this OMG | :OMG: , but I don't think so.
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 
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 

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.