.NET: Converting a String to a GUID

This is just a quick little tip I came across yesterday. I was reading a Guid value out of a database and then passing it to .NET service along with some other data. The column type in the SQL Server database was a standard VARCHAR field, while the service itself was expecting a Guid data type to be passed in. My first thought was that there was a little convert function that would do the work of converting my string to a Guid type, in the same way you can convert variables to integers, strings etc… Quickly I found out this was not the case, and after searching online I came across a solution that was just as simple:

<code lang="csharp[lines]"><br></br>
Guid id = new Guid(yourStringValue);<br></br>

Easy enough, and now I had my Guid data type to pass into the service.

Comments

comments powered by Disqus