1/**////<summary> 2/**//// Generate a new <see cref="Guid"/> using the comb algorithm. 3/**////</summary> 4private Guid GenerateComb() 5...{ 6byte[ ] guidArray = Guid.NewGuid().ToByteArray(); 7 8 DateTime baseDate =new DateTime( 1900, 1, 1 ); 9 DateTime now = DateTime.Now; 10 11// Get the days and milliseconds which will be used to build 12//the byte string 13 TimeSpan days =new TimeSpan( now.Ticks - baseDate.Ticks ); 14 TimeSpan msecs = now.TimeOfDay; 15 16// Convert to a byte array 17// Note that SQL Server is accurate to 1/300th of a 18// millisecond so we divide by 3.333333 19byte[ ] daysArray = BitConverter.GetBytes( days.Days ); 20byte[ ] msecsArray = BitConverter.GetBytes( ( long ) ( msecs.TotalMilliseconds/3.333333 ) ); 22 23// Reverse the bytes to match SQL Servers ordering 24 Array.Reverse( daysArray ); 25 Array.Reverse( msecsArray ); 26 27// Copy the bytes into the guid 28 Array.Copy( daysArray, daysArray.Length -2, guidArray, guidArray.Length -6, 2 ); 30 Array.Copy( msecsArray, msecsArray.Length -4, guidArray, guidArray.Length -4, 4 ); 33returnnew Guid( guidArray ); 34 }