BrownBot Logo BrownBot Head

Convert a String to a GUID in C#

11:01 pm Filed under: C#

This is a simple one that didn’t take all that long to find a solution for but I thought it was worth putting up here anyhow seeing it’s not all that obvious.

To convert most other data types (Strings, Ints, Chars etc) you use the Convert. system function eg.

char myChar = Convert.ToChar(myString);

char myInt = Convert.ToInt(myString);

But GUIDs are treated a little differently, you actually create a new instance seeded with the string value eg.

Guid myGuid = new Guid(myString);

No Comments »

No comments yet.

RSS feed for comments on this post. TrackBack URI

Leave a comment

You must be logged in to post a comment.

Powered by WordPress