79589494

Date: 2025-04-23 21:10:09
Score: 0.5
Natty:
Report link

This tests to see if it has a value (is not null), and if it does, I can set that back to myGuid. If it doesn't, I just set myGuid to a new GUID (00000000-0000-0000-0000-000000000000):

Guid myGuid = SomeProperty.HasValue ? (Guid)SomeProperty : Guid.NewGuid();

You can also do

Guid myGuid = SomeProperty ?? Guid.Empty;

In these ways, you can convert a Guid? to a Guid. And for those who want to downvote this, there's no reason to as this code WORKS. Give an explanation instead of your hit-and-runs.

Reasons:
  • RegEx Blacklisted phrase (2): downvote
  • Long answer (-0.5):
  • Has code block (-0.5):
  • Filler text (0.5): 00000000
  • Filler text (0): 000000000000
  • High reputation (-1):
Posted by: vapcguy