Comparing values of generic types
Hi all!
Consider the following sample:
Code:
public abstract class SomeClass
{
// checks equality of each member in two arrays.
public static bool ArrayEquals<T>(T[] a, T[] b)
{
if (a.Length != b.Length) {
return false;
}
for (int i = 0; i < a.Length; i++) {
if ( a[i] != b[i] ) {
return false;
}
}
return true;
}
}
Now, this function doesn't work, and I quess it's because <T> COULD be a reference type, or a value type. Is there a way to allow only value-types as <T>?
Or, alternately, is there another way of checking the value(not reference) of each entity in a and b?
object.Equals(a[i], b[i]) does not work because it checks the ref.
Thanks!