I have a script called globals.cs where I store global variables that are accessed from other scripts. I have the following class defined there:
public static class business {
static List<businessVal> _list;
static business() {_list = new List<businessVal>();}
public static void Add (businessVal value) {_list.Add(value);}
public static IEnumerable<businessVal> Get () {return _list;}
public static businessVal GetItem (string name) {return _list.SingleOrDefault(li => li.name.Equals(name));}
}
public class businessVal {
public string name {get; set;}
public int income {get; set;}
}
I'm able to add items to the list and return the full list from other scripts. What I'd like to do is to be able to sort the list either by name
or income
before looping through the list elements.
I tried adding a sort function to the class as shown below, but I get an error message when using IComparable saying I cannot implement an interface on a static class. What's the beat way of doing this?
public static class business: IComparable {
// ...
public int CompareTo(businessVal tag) {
return businessVal.income.CompareTo(tag.income);
}
}