I've created a generic interface class and inherit from it with another generic class. The compiler doesn't like my function (see the error within the code).
What am I missing?
I'd like to create objects from ChecksumTruncate12Bit with types ushort, uint and ulong
public interface IChecksum<T>
{
T Checksum(byte[] buffer, int size);
}
public class ChecksumTruncate12Bit<T> : IChecksum<T>
{
public T Checksum(byte[] buffer, int size)
{
T rv = (T)0; // Error CS0030 Cannot convert type 'int' to 'T'
for (int i = 0; i < size; ++i)
{
rv += (T)(buffer[i]); // Error CS0030 Cannot convert type 'byte' to 'T'
rv &= (T)(0x0FFF); // Error CS0030 Cannot convert type 'int' to 'T'
}
return rv;
}
}