How to use Array.sort to sort an array of structs, by a specific element

后端 未结 3 641

Simple, I have a struct like this:

struct bla{
  string name;
  float depth;
}

I have an bla array, and I want to sort by depth, being the

3条回答
  •  我在风中等你
    2021-01-14 01:09

    using System.Linq;

    blas.OrderByDescending(x=>x.depth)
    

    or

    Array.Sort(blas, (x, y) => y.depth.CompareTo(x.depth) );
    

提交回复
热议问题