If you have permission to use your own code, just call memcmp:
static class memcmpsig<T> where T : struct
{
[DllImport("msvcrt.dll", CallingConvention=CallingConvention.Cdecl)]
static extern int memcmp(ref T left, ref T right, UIntPtr count);
}
static class CompareExtension
{
int CompareTo<T>(this T left, T right) { return memcmpsig<T>::memcmp(left, right, Marshal::SizeOf(typeof(T));
}
source
share