conditional-operator

null coalesce operator in VB.Net(8)

一笑奈何 提交于 2019-12-05 19:39:16
i'm afraid that this is a stupid question, but i must assume that i have programmed VB.Net too long and now can't figure out how to convert this C# null coalescing operator into VB.Net: if( Convert.ToBoolean(ViewState[tp.UniqueID + "_Display"] ?? true) == false ){} I know the IIF-Function but i'm not sure how to use it here and if it gives the correct result(in IIF both expressions are being evaluated). Please help to shed light on the dark. EDIT : if you want to see the source of this: forums.asp.net There you can see a solution that generates a Option Strict On disallows implicit conversions

“Cannot be determined because there is no implicit conversion” with ternery if return

三世轮回 提交于 2019-12-05 14:58:51
问题 I have the following ASP.NET Web Api 2 action with a ternary if return: [HttpDelete] public IHttpActionResult Delete() { bool deleted; // ... return deleted ? this.Ok() : this.NotFound(); } I receive a Type of conditional expression cannot be determined because there is no implicit conversion between 'System.Web.Http.Results.OkResult' and 'System.Web.Http.Results.NotFoundResult' when they both implement IHttpActionResult . However if I remove the ternary if, the compiler is happy: if (deleted

if(condition, then, else) in Oracle

孤街浪徒 提交于 2019-12-05 14:50:40
问题 MySQL/MSSQL has a neat little inline if function you can use within queries to detect null values, as shown below. SELECT ... foo.a_field AS "a_field", SELECT if(foo.bar is null, 0, foo.bar) AS "bar", foo.a_field AS "a_field", ... The problem I'm running into now is that this code is not safe to run on an Oracle database, as it seems not to support this inline if syntax. Is there an equivalent in Oracle? 回答1: Use the standard COALESCE function: SELECT COALESCE(foo.bar, 0) as "bar", ... Or use

What is the “?” and “:” sequence actually called? [duplicate]

ε祈祈猫儿з 提交于 2019-12-05 08:28:12
This question already has an answer here: What does '?' do in C++? 7 answers This may be a bonehead question, but I cannot figure out what the ? exp : other_exp sequence is called. Example: int result = (true) ? 1 : 0; I've tried using the Google machine, but it's hard to Googilize for something without knowing what it's called. Thanks! It is called the the conditional operator or alternativly the ternary operator as it a ternary operator (an operator which takes 3 operands (arguments)), and as it's usually the only operator, that does this. It is also know as the inline if (iif), the ternary

Conditional function in APL

余生颓废 提交于 2019-12-05 05:09:40
Is there a symbol or well-known idiom for the conditional function, in any of the APL dialects? I'm sure I'm missing something, because it's such a basic language element. In other languages it's called conditional operator , but I will avoid that term here, because an APL operator is something else entirely. For example C and friends have x ? T : F LISPs have (if x T F) Python has T if x else F and so on. I know modern APLs have :If and friends, but they are imperative statements to control program flow: they don't return a value, cannot be used inside an expression and certainly cannot be

ternary operator doesn't work with lambda functions

∥☆過路亽.° 提交于 2019-12-04 23:31:29
I am assigning to a std::function<double()> a lambda expression. This snippet works if(fn_type==exponential) k.*variable = [=,&k](){ return initial*exp(-k.kstep*par); }; else k.*variable = [=,&k](){ return initial*pow(k.kstep, par); }; whereas if I want to use the ternary operator k.*variable = (fn_type==exponential ? [=,&k](){ return initial*exp(-k.kstep*par); } : [=,&k](){ return initial*pow(k.kstep, par); }); I get the following error: error: no match for ternary ‘operator?:’ in <awfully long template error, because this whole thing is in a class defined in a function...> Is this a gcc bug

How to use Conditional Operation with Nullable Int

我只是一个虾纸丫 提交于 2019-12-04 20:10:25
问题 A small problem. Any idea guys why this does not work? int? nullableIntVal = (this.Policy == null) ? null : 1; I am trying to return null if the left hand expression is True, else 1 . Seems simple but gives compilation error. Type of conditional expression cannot be determined because there is no implicit conversion between null and int . If I replace the null in ? null : 1 with any valid int , then there is no problem. 回答1: Yes - the compiler can't find an appropriate type for the

Compiler error for conditional operator “?:” when used with typecasting operator

白昼怎懂夜的黑 提交于 2019-12-04 19:13:10
问题 Following code is in simplest form: struct X { operator char () const { return 'a'; } }; int main () { X obj, *p = &obj; char a = *p; // ok char c = (true)? *p : 'z'; } This code gives compiler error as, error: operands to ?: have different types ‘X’ and ‘char’ Why *p is not resolved to char when there is no ambiguity in class X for typecasting operator ? Is such spurious error message correct or it's a g++ bug ? [ Update Note: Interestingly this scenario doesn't generate such error] 回答1: It

Using conditional operator in lambda expression in ForEach() on a generic List?

筅森魡賤 提交于 2019-12-04 18:17:31
问题 Is it not allowed to have a conditional operator in a lambda expression in ForEach? List<string> items = new List<string>{"Item 1", "Item 2", "Item I Care About"}; string whatICareAbout = ""; // doesn't compile :( items.ForEach(item => item.Contains("I Care About") ? whatICareAbout += item + "," : whatICareAbout += ""); Compilation error -> "Only assignment, call, increment, decrement, and new object expressions can be used as a statement" Trying to use a normal if doesn't work either: // :(

Can you throw within a conditional expression? (was: How can bounds-checking be extended to multiple dimensions?)

只谈情不闲聊 提交于 2019-12-04 17:13:50
Note: I solved the original problem by realizing a completely different one. See the addendum for the new actual problem, but you can read the previous part for context. This is an extension of one of my previous posts . I made a container class based on that answer: template < typename T, unsigned N0, unsigned ...N > struct array_md { // There's a class template specialization with no extents. // Imagine the various N... components are bracket-enclosed instead // of comma-separated. And if "N..." is empty, then we just have "T" // as the "direct_element_type". (I actually use recursive class