在将int转换为guid时,我在C#和SQL Server中得到了不同的值。
在C#中,我使用以下方法:
public static Guid Int2Guid( int value )
{
byte[] bytes = new byte[16];
BitConverter.GetBytes( value ).CopyTo( bytes, 0 );
return new Guid( bytes );
}
Console.Write( Int2Guid( 1000 ).ToString() );
// writes 000003e8-0000-0000-0000-000000000000
在SQL Server中我使用
select cast(cast(1000 as varbinary(16)) as uniqueidentifier)
-- writes E8030000-0000-0000-0000-000000000000
他们为什么会表现不同呢?