T
Tony Johansson
Hello!
I have this ProductComparerCount class below that compare the
count field for the Product class.
The collection class is named myProdList and is defined like this
List<Product> myProdList = new List<Product>();
The actual sort command look like this
myProdList.Sort(ProductComparerCount.Default);
I can't use the IComparable(CompareTo) because I have some other sorting
also.
Now to my problem when I compile I get the following 2 error
The second error is probably a consequence of the first.
Error 1 The best overloaded method match for
'System.Collections.Generic.List<MediaShop.Product>.Sort(System.Collections.Generic.IComparer<MediaShop.Product>)'
has some invalid arguments F:\C#\Ovningar\MediaShop\Statistik.cs 57 10
MediaShop
Error 2 Argument '1': cannot convert from 'System.Collections.IComparer' to
'System.Collections.Generic.IComparer<MediaShop.Product>'
F:\C#\Ovningar\MediaShop\Statistik.cs 57 33 MediaShop
How can I fix this. I can't understand where I have done any misstake.
class ProductComparerCount : IComparer
{
public static IComparer Default = new ProductComparerCount();
public int Compare(object x, object y)
{
return Comparer.Default.Compare(
((Product)x).Count,((Product)y).Count);
}
}
//Tony
I have this ProductComparerCount class below that compare the
count field for the Product class.
The collection class is named myProdList and is defined like this
List<Product> myProdList = new List<Product>();
The actual sort command look like this
myProdList.Sort(ProductComparerCount.Default);
I can't use the IComparable(CompareTo) because I have some other sorting
also.
Now to my problem when I compile I get the following 2 error
The second error is probably a consequence of the first.
Error 1 The best overloaded method match for
'System.Collections.Generic.List<MediaShop.Product>.Sort(System.Collections.Generic.IComparer<MediaShop.Product>)'
has some invalid arguments F:\C#\Ovningar\MediaShop\Statistik.cs 57 10
MediaShop
Error 2 Argument '1': cannot convert from 'System.Collections.IComparer' to
'System.Collections.Generic.IComparer<MediaShop.Product>'
F:\C#\Ovningar\MediaShop\Statistik.cs 57 33 MediaShop
How can I fix this. I can't understand where I have done any misstake.
class ProductComparerCount : IComparer
{
public static IComparer Default = new ProductComparerCount();
public int Compare(object x, object y)
{
return Comparer.Default.Compare(
((Product)x).Count,((Product)y).Count);
}
}
//Tony