IComparer<> through a 'static' definition ?

M

Michel Walsh

I got a class which implements a comparison test:

public class CompareMarque : ICompare<Marque>
{
public int Compare( Marque x, Marque y)
{
...some funny rules
}


// but I also want to be able to use the same funny rules in a static way,
so I added:

public static int Comparez( Marque x, Marque y)
{
... SAME funny rules
}
}



Question: is there a way to AVOID code duplication of the "funny rules"
(since it seems that a static method CANNOT be used to implement ICompare) ?



Vanderghast, Access MVP
 
M

Michel Walsh

.... well, can also use a call to the static definition within the non-static
definition... doh... Looking too hard in the wrong direction, I guess...
Sorry for the bandwidth.


Vanderghast, Access MVP
 
S

Stefan Hoffmann

hi Michael,

Michel said:
public class CompareMarque : ICompare<Marque>
{
public int Compare( Marque x, Marque y)
{
}
// but I also want to be able to use the same funny rules in a static way,
so I added:
public static int Comparez( Marque x, Marque y)
{
}
}
This should be a clean solution:

public class CompareMarque : ICompare<Marque>
{
int ICompare<Marque>.Compare( Marque x, Marque y)
{
return Compare(x, y);
}

public static int Compare( Marque x, Marque y)
{
return 0;
}
}



mfG
--> stefan <--
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top