?? and Guid

  • Thread starter Thread starter shapper
  • Start date Start date
S

shapper

Hello,

I am inserting an item on a XML file and I have something like this:

paper.ID ?? Guid.NewGuid()

Basically my idea was that if paper.ID is null then create a new Guid.

It says it is not possible to use ?? with Guid. Is there another
option to do this?

Thanks,
Miguel
 
Hi Miguel,

can you show code please,...

Regards

Kerem

--
-----------------------
Beste Grüsse / Best regards / Votre bien devoue
Kerem Gümrükcü
Latest Project:http://www.codeplex.com/restarts
Latest Open-Source Projects:http://entwicklung.junetz.de

album.Add(new XElement("img",
new XAttribute("id", paper.Slide.SlideID ??
Guid.NewGuid())
));

paper.Slide is an object. So if it's SlideID, which is Guid, had no
value assigned then a new guid is used.

This seemed logic to me until I got the error :-)
 
shapper said:
album.Add(new XElement("img",
new XAttribute("id", paper.Slide.SlideID ??
Guid.NewGuid())
));

paper.Slide is an object. So if it's SlideID, which is Guid, had no
value assigned then a new guid is used.

This seemed logic to me until I got the error :-)

Since SlideID is a Guid it cannot be null. Therefore SlideID ?? makes no
sense. Now, if you make SlideID a Guid? (nullable Guid) your code should
work.
 
shapper said:
Well, I can do this:

Guid id = new Guid();

And yet the Guid value is not defined.

Yes it is. That's a well-defined Guid of all zeroes. It's sort of like
the empty string of Guids.
 
Since SlideID is a Guid it cannot be null.  Therefore SlideID ?? makes no
sense.  Now, if you make SlideID a Guid? (nullable Guid) your code should
work.

I see. I think I will let it this way because it is generated by Linq
To SQL dbml and I prefer to touch the least possible in the generated
code.
 
Back
Top