简体   繁体   中英

How Array.Sort sort a class that contains strings and doubles?

In some code I'm looking through the writer goes:

Individual[] candidates = new Individual[tournSize];
for (int i = 0; i < tournSize; ++i)
candidates[i] = population[indexes[i]];
Array.Sort(candidates);

Which property would it sort it by if the class contains: string s; and double d.

在文档https://msdn.microsoft.com/zh-cn/library/6tf1f0bc(v=vs.110).aspx中指定,每个元素必须支持IComparable ,在这种情况下,结果将按照这些定义进行排序,并且如果元素不支持该接口,则结果不确定。

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM