Jump to content
K_Drive

Is this a type of "if" statement?

Recommended Posts

I am going through a book on C# and ASP.Net.I ran across a statement that I don't quite understand.The book does not explain it.From the context I am assuming that it is an "if" statement. Here it is:

shippingRegion = (profile.ShippingRegion == null || profile.ShippingRegion == "" ? "1" : profile.ShippingRegion);

Here is the code around it:

		ProfileCommon profile = HttpContext.Current.Profile as ProfileCommon;		address1 = profile.Address1;		address2 = profile.Address2;		city = profile.City;		region = profile.Region;		postalCode = profile.PostalCode;		country = profile.Country;>		shippingRegion = (profile.ShippingRegion == null || profile.ShippingRegion == "" ? "1" : profile.ShippingRegion);		dayPhone = profile.DayPhone;		evePhone = profile.EvePhone;		mobPhone = profile.MobPhone;		email = Membership.GetUser(profile.UserName).Email;

If I need to add more explanation or code, please let me know. Thanks. K

Share this post


Link to post
Share on other sites

Yes, it's a kind of an if statement. Formally called "ternary operator". The syntax is

condition ? if-true : if-false

See this MSDN page for details.

  • Like 1

Share this post


Link to post
Share on other sites

I'd rather call it the conditional operator. Because in the unlikely case that another ternary operator shows up, the term "ternary operator" will become ambiguous.

Share this post


Link to post
Share on other sites

Hmm... it actually seems the MSDN page agrees with you Ingolme... I used the other term anyway not only because of PHP, but also because that's the term I used on the MSDN search to find that page.Personally, I'm not sure that "ambiguity in the context of other operators" should ever really an issue in naming an operator. Bitwise operators, if mixed with arithmetic operators can become ambiguous when a programmer tries to interpret them. Arithmetic operators alone can sometimes do that.But that's purely a philosophical issue (with no practical impact), so we can agree to disagree.

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...

×
×
  • Create New...