What is the difference between these two ways of converting a string to System.Guid
? Is there a reason to choose one over the other?
var myguid
Use the version that is the most readable to you. The two are implemented almost exactly the same way.
The only real difference is that the constructor initializes itself to Guid.Empty
before attempting the parse. However, the effective code is identical.
That being said, if the Guid
is coming from user input, then Guid.TryParse
would be better than either option. If this Guid
is hard coded, and always valid, either of the above are perfectly reasonable options.