[英]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; 如果该类包含以下内容,将按哪个属性对其进行排序:string s; and double d.
d。
在文档https://msdn.microsoft.com/zh-cn/library/6tf1f0bc(v=vs.110).aspx中指定,每个元素必须支持IComparable
,在这种情况下,结果将按照这些定义进行排序,并且如果元素不支持该接口,则结果不确定。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.