简体   繁体   中英

C# - Sorting ObservableCollection “'utils' is inaccesible due to its protection level”

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.

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
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM