K_Drive Posted October 21, 2012 Share Posted October 21, 2012 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 Link to comment Share on other sites More sharing options...
boen_robot Posted October 21, 2012 Share Posted October 21, 2012 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. 1 Link to comment Share on other sites More sharing options...
Ingolme Posted October 21, 2012 Share Posted October 21, 2012 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. Link to comment Share on other sites More sharing options...
boen_robot Posted October 21, 2012 Share Posted October 21, 2012 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. Link to comment Share on other sites More sharing options...
K_Drive Posted October 22, 2012 Author Share Posted October 22, 2012 Thank you for the replies and for the MSDN reference. I will read more. K Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now