0

I am trying to sort my observable collection by numbers. I found here on this forum this post: How do I sort an observable collection?

Everything is working fine till the line:

return Utils.LogicalStringCompare(a.Penize, b.Penize);

Where i get this error: "'Utils' is inaccesible due to its protection level."

My code:

static class Extensions
{
    public static void Sort<T>(this ObservableCollection<T> collection) where T : IComparable
    {
        List<T> sorted = collection.OrderBy(num => num).ToList();
        for (int i = 0; i < sorted.Count(); i++)
            collection.Move(collection.IndexOf(sorted[i]), i);
    }
}
public class Uzivatel : IComparable
{
    public int CompareTo(object o)
    {
        Uzivatel a = this;
        Uzivatel b = (Uzivatel)o;
        return Utils.LogicalStringCompare(a.Penize, b.Penize);
    }
    public int Penize{get;set;}
}

Can somebody help me with this please ? (Problem is still there even when i set that Extensions class to public.)

I dont want to use this insted, because its badly sorting numbers (1005 < 15 -_-):

return string.Compare(a.Penize.ToString(), b.Penize.ToString());

I will be happy for any help you will give me.

Community
  • 1
  • 1

1 Answers1

1

Make sure your class Utils is accessible in Uzivatel class. Use public access modifier for making it accessible. like:

public class Utils 
{
 //Your properties and methods
}
M.S.
  • 4,283
  • 1
  • 19
  • 42
error_handler
  • 1,191
  • 11
  • 19