我有如下的C#类:
public class ClassInfo {
public string ClassName;
public int BlocksCovered;
public int BlocksNotCovered;
public ClassInfo() {}
public ClassInfo(string ClassName, int BlocksCovered, int BlocksNotCovered)
{
this.ClassName = ClassName;
this.BlocksCovered = BlocksCovered;
this.BlocksNotCovered = BlocksNotCovered;
}
}
我有如下的C#ClassInfo()列表
List<ClassInfo> ClassInfoList;
如何基于BlocksCovered对ClassInfoList进行排序?
最佳答案
这将返回由List<ClassInfo>
排序的BlocksCovered
:
var results = ClassInfoList.OrderBy( x=>x.BlocksCovered).ToList();
请注意,您确实应该将
BlocksCovered
设置为属性,现在您具有公共字段。