Author Topic: changes to List Class  (Read 2576 times)

Zaibach333

  • Guest
changes to List Class
« on: February 16, 2013, 05:57:46 AM »
Hello,

I quickly adapted to using size instead of Count with lists using this plugin. It also took some time to figure out a way to serialize Lists (by converting them to arrays first).  but now I'm not getting my Lists to Sort,  So I'm curious if Sorting is different or if Linq will work with these TNet Lists.

Loving the plugin by the way.

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: changes to List Class
« Reply #1 on: February 16, 2013, 01:41:22 PM »
Sorting TNet Lists is really simple. You need to create a comparison function like this:
  1. static int CompareFunction (YourListMember a1, YourListMember a2)
  2. {
  3.     return a1.CompareTo(a2);
  4. }
  5.  
then do list.Sort(CompareFunction). Keep in mind that this assumes that "YourListMember" has the CompareTo Function. In case of basic types like int, float, bool etc -- they all have it. For custom classes you will need to write your own comparison logic that returns -1, 0, or 1.

Zaibach333

  • Guest
Re: changes to List Class
« Reply #2 on: February 18, 2013, 04:28:47 AM »
works, thanks much!