?? and Guid

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
 
S

shapper

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 :)
 
M

Morten Wennevik [C# MVP]

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.
 
J

Jon Skeet [C# MVP]

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.
 
S

shapper

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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads

Check Guid 1
Byte[] and File 6
String.Join and Linq 1
Alternatives to "Guid" 8
Linq. Where 1
Class and XML file. Very strange problem. 1
Remove from List 2
Need advice on naming repositories methods. 3

Top