For this specific case I recommend you make a IComparer<T>
.
public class MyStringComparer : IComparer<string>
{
public int Compare(string x, string y){
string[] xs = x.Split('.'), ys = y.Split('.');
int x1, y1,
comp;
//assumi que antes do ponto sempre é um int então
if(int.TryParse(xs[0], out x1) && int.TryParse(ys[0], out y1)){
comp = x1.CompareTo(y1);
return comp == 0 ? string.Compare(xs[1], ys[1]) : comp;
}
comp = string.Compare(xs[0], ys[0]);
return comp == 0 ? string.Compare(xs[1], ys[1]) : comp;
}
}
Here’s a example of it working :)
That is to say
string
, right? You can ensure that always always in this format and will have at most two digits before decimal point?– Maniero