A
Author
Well, I was trying out this code snippet from
http://msdn.microsoft.com/en-us/library/system.collections.icomparer.aspx
..
using System;
using System.Collections;
public class SamplesArrayList {
public class myReverserClass : IComparer {
// Calls CaseInsensitiveComparer.Compare with the parameters
reversed.
int IComparer.Compare( Object x, Object y ) {
return( (new CaseInsensitiveComparer()).Compare( y, x ) );
}
}
public static void Main() {
[snip]
}
}
Why do we have to explicitly qualify the Compare method as below
int IComparer.Compare( Object x, Object y )
when we implement the Compare method of the IComparer interface?
If I remove qualification, and simply do
int Compare( Object x, Object y )
I get a compile time error which says:
"Cannot implement an interface member because it is not public."
I don't understand this. Please kindly advise. TIA.
http://msdn.microsoft.com/en-us/library/system.collections.icomparer.aspx
..
using System;
using System.Collections;
public class SamplesArrayList {
public class myReverserClass : IComparer {
// Calls CaseInsensitiveComparer.Compare with the parameters
reversed.
int IComparer.Compare( Object x, Object y ) {
return( (new CaseInsensitiveComparer()).Compare( y, x ) );
}
}
public static void Main() {
[snip]
}
}
Why do we have to explicitly qualify the Compare method as below
int IComparer.Compare( Object x, Object y )
when we implement the Compare method of the IComparer interface?
If I remove qualification, and simply do
int Compare( Object x, Object y )
I get a compile time error which says:
"Cannot implement an interface member because it is not public."
I don't understand this. Please kindly advise. TIA.