471,330 Members | 1,808 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,330 software developers and data experts.

?? and Guid

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
Sep 8 '08 #1
9 1255
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
-----------------------
"This reply is provided as is, without warranty express or implied."
"shapper" <md*****@gmail.comschrieb im Newsbeitrag
news:cb**********************************@d45g2000 hsc.googlegroups.com...
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
Sep 8 '08 #2
A Guid cannot be null, unless you declare it Guid?.

"shapper" <md*****@gmail.comwrote in message
news:cb**********************************@d45g2000 hsc.googlegroups.com...
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
Sep 8 '08 #3
On Sep 8, 3:42*am, Kerem Gümrükcü <kareem...@hotmail.comwrote:
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
-----------------------
"This reply is provided as is, without warranty express or implied."
"shapper" <mdmo...@gmail.comschrieb im Newsbeitragnews:cb******************************** **@d45g2000hsc.googlegroups.com...
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
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 :-)
Sep 8 '08 #4
On Sep 8, 4:07*am, "Family Tree Mike"
<FamilyTreeM...@ThisOldHouse.comwrote:
A Guid cannot be null, unless you declare it Guid?.

"shapper" <mdmo...@gmail.comwrote in message

news:cb**********************************@d45g2000 hsc.googlegroups.com...
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
Well, I can do this:

Guid id = new Guid();

And yet the Guid value is not defined.

Sep 8 '08 #5

"shapper" wrote:
On Sep 8, 3:42 am, Kerem Gümrükcü <kareem...@hotmail.comwrote:
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
-----------------------
"This reply is provided as is, without warranty express or implied."
"shapper" <mdmo...@gmail.comschrieb im Newsbeitragnews:cb******************************** **@d45g2000hsc.googlegroups.com...
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

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.

--
Happy Coding!
Morten Wennevik [C# MVP]
Sep 8 '08 #6
Hi shapper,

Yes, but cant Guid id = null. Basicaly, ?? aplied for reference and nullable
types.
http://msdn.microsoft.com/en-us/libr...24(VS.80).aspx

Regards, Alex
blog: devkids.blogspot.com
Well, I can do this:

Guid id = new Guid();

And yet the Guid value is not defined.

Sep 8 '08 #7
shapper <md*****@gmail.comwrote:
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.

--
Jon Skeet - <sk***@pobox.com>
Web site: http://www.pobox.com/~skeet
Blog: http://www.msmvps.com/jon.skeet
C# in Depth: http://csharpindepth.com
Sep 8 '08 #8
On Sep 8, 6:08*am, Morten Wennevik [C# MVP]
<MortenWenne...@hotmail.comwrote:
"shapper" wrote:
On Sep 8, 3:42 am, Kerem Gümrükcü <kareem...@hotmail.comwrote:
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
-----------------------
"This reply is provided as is, without warranty express or implied."
"shapper" <mdmo...@gmail.comschrieb im Newsbeitragnews:cb******************************** **@d45g2000hsc.googlegroups.com...
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
* * * 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.

--
Happy Coding!
Morten Wennevik [C# MVP]
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.
Sep 8 '08 #9
On Sep 8, 6:22*am, Jon Skeet [C# MVP] <sk...@pobox.comwrote:
shapper <mdmo...@gmail.comwrote:
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.

--
Jon Skeet - <sk...@pobox.com>
Web site:http://www.pobox.com/~skeet*
Blog:http://www.msmvps.com/jon.skeet
C# in Depth:http://csharpindepth.com
You are completely right!

Thanks,
Miguel
Sep 8 '08 #10

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

4 posts views Thread by Louis Frolio | last post: by
6 posts views Thread by Jim Heavey | last post: by
9 posts views Thread by Rene | last post: by
14 posts views Thread by Nak | last post: by
5 posts views Thread by George | last post: by
1 post views Thread by Wolf | last post: by
5 posts views Thread by Michael Primeaux | last post: by
4 posts views Thread by Marc | last post: by
reply views Thread by rosydwin | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.