Whats wrong with this syntax? I can't figure it out for the life of me!
String str = ((String)result[i][1] ? (String)result[i][1] : "");
Error 7 Cannot implicitly convert type 'string' to 'bool'
its doing me trunk in :p
Whats wrong with this syntax? I can't figure it out for the life of me!
String str = ((String)result[i][1] ? (String)result[i][1] : "");
Error 7 Cannot implicitly convert type 'string' to 'bool'
its doing me trunk in :p
If I'm not mistaken I believe its telling you that its not in a String format its in a Bool format.
Substitute String for Bool and see what happens...
If it doesn't work then I'm sorry, and I hope someone can help resolve this issue for you. I am new to C# so don't get angry at me. I just made the assumption looking at the error message.
- Poab9200
The condition must evaluate to a boolean type. Unless result[1] is already a boolean type, you can't use it without a relational test:
String str = ( (String)result[i][1] != null ? (String)result[i][1] : "" );
Also, what type is result[1] such that a cast to String is required?
the syntax is
<boolean expression> ? <staement1> : <statement2>;
now here depending on the value of boolean expression one statement is choosen for execution. if this is in C/C++ it can be any boolean expression or any statement with some integer value or no value at all(in this case it is considered true always).
but if the code is for java,it should essentially be a boolean expression.
>in C/C++
This is the C# forum.
>it can be any boolean expression or any statement with some integer value
IIRC, the description is "any expression that can be contextually converted to bool".
>or no value at all(in this case it is considered true always)
This is incorrect. Failure to provide a condition expression is a syntax error.
>but if the code is for java
This is still the C# forum. Conveniently enough for you, the Java rule matches C#.
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.