El tipo de datos de marca de tiempo de MS SQL Server es semánticamente equivalente a binario (8) (si no se puede nulos) o varbinary (8) (si se puede escribir con nulo). Ergo, compárelos como matrices de bytes.
Sin mencionar que hay gastos generales involucrados en la conversión a largo. Podrías escribir algún código inseguro para obtener la dirección de las matrices de bytes, convertirlas en punteros largos y desreferenciarlas en longs, PERO hacerlo con seguridad significa anclarlas en la memoria y un montón de código feo para hacer algo esencialmente simple (y probablemente no más rápido que usar BitConverter).
La forma más rápida de hacerlo, si el rendimiento es realmente tan crítica, la forma más rápida sería hacer la comparación utilizando la función de la biblioteca estándar de C memcmp() a través de P/Invoke:
using System;
using System.Runtime.InteropServices;
namespace TestDrive
{
class Program
{
static void Main()
{
byte[] a = { 1,2,3,4,5,6,7,8} ;
byte[] b = { 1,2,3,4,5,0,7,8} ;
byte[] c = { 1,2,3,4,5,6,7,8} ;
bool isMatch ;
isMatch = TimestampCompare(a , b) ; // returns false
isMatch = TimestampCompare(a , c) ; // returns true
return ;
}
[DllImport("msvcrt.dll", CallingConvention=CallingConvention.Cdecl)]
static extern int memcmp(byte[] x , byte[] y , UIntPtr count) ;
static unsafe bool TimestampCompare(byte[] x , byte[] y)
{
const int LEN = 8 ;
UIntPtr cnt = new UIntPtr((uint) LEN) ;
// check for reference equality
if (x == y) return true ;
if (x == null || x.Length != LEN || y == null || y.Length != LEN)
{
throw new ArgumentException() ;
}
return (memcmp( x , y , cnt) == 0 ? true : false) ;
}
}
}
@Nicholas muy cool –
Jest un programador C de la escuela vendida B ^) –
@Nicholas +1 es muy bonito pero me gustaría evitar el código inseguro. –