What is the best method of getting Int32 from first four bytes of GUID?
Question
I'm just wondering if it exists better solution for this.
BitConverter.ToInt32(sample_guid.ToByteArray(), 0)
Solution
I don't think there's a better solution than this.
OTHER TIPS
I don't know if it's better, but it is easier to read:
Int32.Parse(sample_guid.ToString().SubString(0,1));
I'm a junior developer, admittedly, but the above reads easier to me than a byte conversion, and on a modern computer it would run indistinguishably quickly.
Dunno about a better solution, but I hope you don't intend to use that Int32 as a random (or unique) value.
You cannot depend on any sub part of a Guid to be unique. Guid is assumed to be unique, only in its entirety.
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow