先是 Y_FaceItem类

using DlibDotNet;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class Y_FaceItem : MonoBehaviour
{
    public float finalValue;
    public Texture2D faceTextrue;
    public int id;
    public string faceImage;
    public Matrix<float> code;
}

然后是排序的应用方法

List<Y_FaceItem> itemList = new List<Y_FaceItem>();
Y_FaceItem item = new Y_FaceItem();
item.finalValue = 39;
Y_FaceItem item1 = new Y_FaceItem();
item1.finalValue = 19;
Y_FaceItem item2 = new Y_FaceItem();
item2.finalValue = 29;

//itemList.Add(item as Y_FaceItem);
//itemList.Add(item1 as Y_FaceItem);
//itemList.Add(item2 as Y_FaceItem);
itemList.Add(item  );
itemList.Add(item1  );
itemList.Add(item2  );


Debug.LogError("AAAAAAAAAAAAAAA");
foreach (var _i in itemList)
{
    Debug.LogError(_i.finalValue);
}

Debug.LogError("BBBBBBBBBBBBBB");
var sortlist = itemList.OrderBy(o => o.finalValue).ToList();//升序
foreach (var _i in sortlist)
{
    Debug.LogError(_i.finalValue);
}

Debug.LogError("CCCCCCCCCCCCC");
var sortlist1 = itemList.OrderByDescending(o => o.finalValue).ToList();//降序
foreach (var _i in sortlist1)
{
    Debug.LogError(_i.finalValue);
}

Debug.LogError("DDDDDDDDDDDDD");
foreach (var _i in itemList)
{
    Debug.LogError(_i.finalValue);
}

 

补充:


//升序 在finalValue相同时, 以id的升序排序
//var sortlist = faceItemList.OrderBy(o => o.finalValue).ThenBy(t => t.id).ToList();

posted on 2024-03-20 15:45  凌落成迷  阅读(12)  评论(0编辑  收藏  举报