Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

> A simple "new Guid()" gives you all-zeroes

In C#, to have all zeroes, you would do "Guid.Empty"



(continued from my comment above) Apologies, I am missing some text on here. No sure what happened. I might have deleted before I submitted. I cannot edit this comment, but I need to clarify and correct it...

"new Guid()" is equiverlant "Guid.Empty"

Personally, I would prefer writing "Guid.Empty" as it is cleaner. It also helps ensure you understand reading other developers code... their intensions.

Afterall, a lesser experienced developer may not know (or simply forgot) that "new Guid()" does not create a new, unique value. So writing "new Guid()" looks more misleading.

var myGuid1 = new Guid(); // all zeroes, or a value?

var myGuid2 = Guid.Empty; // Ah.. all zeroes.

It is ESPECIALLY cleaner when doing comparison :-

if(myGuid2 == Guid.Empty) { }

To set a Guid, you would do :-

myGuid2 = Guid.NewGuid(); // This makes sense.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: