VB.NET Object Type Analysis for GUID Type

How can I convert an object type to a GUID type in VB.NET?

+4
source share
3 answers

I'm not sure what exactly you want, but this may help:

Dim g = CType(obj, System.Guid) 

If you want to convert a string to Guid :

 Dim g = New Guid(myString) 
+9
source

If you want to create an object as a new guid, use the following call:

 dim objvar as guid = System.GUID.NewGuid() 

Edit Your question is a little unclear when you say "convert." If you already have an object created and assigned, use DirectCast to create an object that will be recognized by Visual Studio.

+1
source

The Mehrdad sample will work, however it is always better to declare a data type for all your variables:

 Dim g As Guid = objectVariable 

In this case, there is no need to use CType or DirectCast.

-3
source

All Articles