• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 2037
  • Last Modified:

System.Guid.NewGuid() created empty guid... why?

Dim symbol_guid As Guid = System.Guid.NewGuid()

why when i debug above code i get empty string?
thanks
0
JSW21
Asked:
JSW21
3 Solutions
 
Mike TomlinsonMiddle School Assistant TeacherCommented:
Use the ToString() method instead?
    Dim symbol_guid As String = System.Guid.NewGuid().ToString
    '                  ^^^^^^                        ^^^^^^^^^

Open in new window

0
 
YarxCommented:
You shouldn't get an empty string if the object type is Guid. I tried the exact same logic and it worked fine for me. However if you're looking to write it out to the screen you'll likely want to display it as a string like mentioned above, but leave it as a Guid for the datatype. It'll make tracking down errors and other problems a lot easier. Also, use Guid.Empty for checking if a Guid is set or not.

The below example is C# but it should give you the jist of it.

//This will give you an empty guid
System.Guid g = new System.Guid();
Write(g == System.Guid.Empty); //will be true

//This will generate a guid and save it to the variable
g = System.Guid.NewGuid();
Write(g == System.Guid.Empty); //will be false

//Use .ToString() when trying to display it.
Write(g.ToString());

Open in new window

0
 
Anil GolamariCommented:
vb.net: dim g as string = System.Guid.NewGuid().ToString()

C#: string outputstring = System.Guid.NewGuid().ToString();

You need make the datatype to string as mentioned by Idle_mind
0
 
JSW21Author Commented:
Actually I Debug it via - Locals window...
The Value is really in Empty...
But when use tostring the value will be shown...

Also i read from other blog it says that it VS2008 bug ... but value are there... only it will not show in debug screen.

Thanks ALL
0

Featured Post

Receive 1:1 tech help

Solve your biggest tech problems alongside global tech experts with 1:1 help.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now