Jump to content

Null coalescing operator ? in C#

Whether you're a seasoned veteran or a struggling beginner, Web Radiance is the web development and web design forum for you. You'll find answers to all your HTML, CSS, SEO, and Programming needs. Pull up a chair and stay awhile.

Page 1 of 1
  • You cannot start a new topic
  • This topic is locked

Null coalescing operator ? in C# Rate Topic: -----

#1 User is offline   Catalyst 

  • Codesmith
  • Group: Administrators
  • Posts: 1,049
  • Joined: 04-April 06
  • Gender:Male
  • Location:San Diego

Posted 18 August 2006 - 12:28 AM

For those times when you need to check for a null and return a string if it is null there's the null coalescing operator ??

string myStr = "The variable is:" + (x ?? "null");
0

#2 User is offline   ShakingSpirit 

  • Pedantic Whinger
  • Group: Members
  • Posts: 237
  • Joined: 01-August 06
  • Gender:Male
  • Location:Southampton, UK

Posted 02 September 2006 - 05:47 PM

oo, I'll have to remember that ^_^
I've only been learning c# for a few weeks (I didn't like VB, and C#'s 'VB-feel' put me off), but I can see this will cut out a lot of pointless
if (myVariable == null)
	do stuff;
else 
	do otherStuff;


^_^

EDIT: Bah, need to use code tags for my indentation to show v_v
EDIT2: As a veteran C++ coder, I can't help reading a simple if-else in C# without wanting to stick a load of curly braces in ^.^
EDIT3:
if (myVariable == 0) {
	do stuff;
  }
  else {
   do otherStuff;
  }

:D
EDIT4: I know I should have used 'count', or 'ptr', but I was keeping inline with the C# example >8(
EDIT5: Ok, no more coffee for me....

This post has been edited by ShakingSpirit: 02 September 2006 - 05:53 PM

QUOTE(MSN)
Benbramz says: i had orgasmic thoughts at the excitement of that
0

#3 User is offline   Catalyst 

  • Codesmith
  • Group: Administrators
  • Posts: 1,049
  • Joined: 04-April 06
  • Gender:Male
  • Location:San Diego

Posted 02 September 2006 - 06:35 PM

lol
0

Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • This topic is locked

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users