| | |
?: syntax problem
Please support our C# advertiser: Intel Parallel Studio Home
![]() |
•
•
Join Date: Dec 2004
Posts: 489
Reputation:
Solved Threads: 5
Whats wrong with this syntax? I can't figure it out for the life of me!
its doing me trunk in :p
C# Syntax (Toggle Plain Text)
String str = ((String)result[i][1] ? (String)result[i][1] : "");
•
•
•
•
Error 7 Cannot implicitly convert type 'string' to 'bool'
•
•
Join Date: Aug 2008
Posts: 33
Reputation:
Solved Threads: 1
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
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
Last edited by Poab9200; Aug 28th, 2008 at 9:54 am.
The condition must evaluate to a boolean type. Unless result[i][1] is already a boolean type, you can't use it without a relational test:
Also, what type is result[i][1] such that a cast to String is required?
C# Syntax (Toggle Plain Text)
String str = ( (String)result[i][1] != null ? (String)result[i][1] : "" );
Last edited by Narue; Aug 28th, 2008 at 9:56 am.
I'm here to prove you wrong.
•
•
Join Date: May 2008
Posts: 8
Reputation:
Solved Threads: 2
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.
<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#.
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#.
I'm here to prove you wrong.
![]() |
Similar Threads
- problem in deleting (PHP)
- Syntax problem! (PHP)
- Insert Into Syntax Problem (MS SQL)
- asp redirect help I think it is a syntax issue (Legacy and Other Languages)
- Need help with the syntax problem (PHP)
- amigious problem with fstream (C++)
- Problem with moving integers to a single formatted string (C)
Other Threads in the C# Forum
- Previous Thread: Changing a database from Windows Authentication to use Username and Password
- Next Thread: create crystal report in c# using mysql
| Thread Tools | Search this Thread |
.net access ado.net algorithm array barchart bitmap box broadcast buttons c# cast check checkbox client color combobox control conversion csharp custom database datagrid datagridview dataset datetime degrees development draganddrop drawing encryption enum event excel file files form format forms function gdi+ httpwebrequest image index input install java label list listbox listener mailmerge mandelbrot math mouseclick mysql operator path photoshop picturebox pixelinversion post programming radians regex remote remoting richtextbox robot save saving serialization server sleep socket sockets sql sql-server statistics stream string stringformatting table tcp text textbox thread time timer treeview update usercontrol validation view visualstudio webbrowser windows winforms wpf xml






