c# OrderBy对象数组排序

public class CmdInfo
{
    [HideLabel]
    [GUIColor("GetColor")]
    public string Name;
    [HideInInspector]
    public CmdType CurType;

    public CmdInfo(string name, CmdType curType)
    {
        this.Name = name;
        this.CurType = curType;
    }
}

public class Demos
{
	public CmdInfo[] Lists;
	public CmdInfo[] SortByStr(CmdInfo[] strs)
	{
		return (from i in Lists orderby i.Name descending select i).ToArray();
	}
}

对Lists 对象数组 按照属性 Name 排序

descending 表示 按字母 降序排序,不加这个参数 则默认升序排序

Lists = (from i in Lists orderby i.Name descending select i).ToArray();

在这里插入图片描述


版权声明:本文为qq_37682160原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接和本声明。