S
shapper
Hello,
I am creating a validation class and I defined a few rules. One is the
following:
public static bool Equal<T>(T value, T compare) where T : struct,
IComparable<T> {
return value.CompareTo(compare) == 0;
}
I use this rule to compare two values: strings, ints, doubles, ...
However, when I use:
Rule.Equal("a", "a")
I get the error:
The type 'string' must be a non-nullable value type in order to use it
as parameter 'T' in the generic type or method
'MyApp.Validation.Rule.Equal<T>(T, T)'
What am I doing wrong?
Can't I create a general rule like this?
Thanks,
Miguel
I am creating a validation class and I defined a few rules. One is the
following:
public static bool Equal<T>(T value, T compare) where T : struct,
IComparable<T> {
return value.CompareTo(compare) == 0;
}
I use this rule to compare two values: strings, ints, doubles, ...
However, when I use:
Rule.Equal("a", "a")
I get the error:
The type 'string' must be a non-nullable value type in order to use it
as parameter 'T' in the generic type or method
'MyApp.Validation.Rule.Equal<T>(T, T)'
What am I doing wrong?
Can't I create a general rule like this?
Thanks,
Miguel