Reputation: 61
i see diffrent results when using LINQ's OrderBy
function on a list in .NET and Visual Studio's Immediate window:
Info
Code
var l = new List<string>() {
"a-test.de",
"a.de"
};
Console.WriteLine(l.OrderBy(e => e).ToList().First());
Result when running the programm
Output is "a-test.de"
Result when using the immediate window
If i set a debugger after the console output and i run l.OrderBy(e => e).ToList().First()
within the immediate window the output is "a.de"
The question
What am i missing? :)
Thank you very much
Upvotes: 2
Views: 137
Reputation: 171
I suppose it depends on your current culture
Try to specify comparer for OrderBy
var l = new List<string>() {
"a-test.de",
"a.de"
};
Console.WriteLine(l.OrderBy(e => e, StringComparer.Ordinal).ToList().First());
It should achieve the same behavior
Upvotes: 2