Guid.Parse() or new Guid()?

Asked

Viewed 177 times

7

What’s the main difference between using the options Guid.Parse() or new Guid() to convert a string in a Guid?

And which of the two approaches would be best used?

var usuarioId = new Guid(User.Identity.GetUserId())

Or

var usuarioId = Guid.Parse(User.Identity.GetUserId())

1 answer

7


Essentially none except for the fact that one is a builder and the other is a manufacturing method.

Builder’s source.

Source of the Factory Method (this is called from the original just above its source, only checking whether the string is valid). Note that the code already uses C# 7.x optimizations

In both those who do the parse is the intern TryParseGuid().

Documentation.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.