How would I sort through an array of structs?

后端 未结 3 1805
后悔当初
后悔当初 2020-12-21 06:37

I have a struct containing song data:

public struct uLib
    {
        public string Path;
        public string Artist;
        public string Title;
                


        
3条回答
  •  南笙
    南笙 (楼主)
    2020-12-21 07:29

    Assuming uLibs is an IEnumerable, you can try this:

    uLibs.OrderBy(i => i.Artist)
    

    This sorts the uLib instances by using a key; in this case, you've selected Artist to be the key to compare against. Similar sorting is possible against your other fields.

提交回复
热议问题