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
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
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.