?: syntax problem

Please support our C# advertiser: Intel Parallel Studio Home
Reply

Join Date: Dec 2004
Posts: 489
Reputation: Acidburn is an unknown quantity at this point 
Solved Threads: 5
Acidburn Acidburn is offline Offline
Posting Pro in Training

?: syntax problem

 
0
  #1
Aug 28th, 2008
Whats wrong with this syntax? I can't figure it out for the life of me!

  1. 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
Reply With Quote Quick reply to this message  
Join Date: Aug 2008
Posts: 33
Reputation: Poab9200 is an unknown quantity at this point 
Solved Threads: 1
Poab9200 Poab9200 is offline Offline
Light Poster

Re: ?: syntax problem

 
0
  #2
Aug 28th, 2008
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
Last edited by Poab9200; Aug 28th, 2008 at 9:54 am.
Reply With Quote Quick reply to this message  
Join Date: Sep 2004
Posts: 7,752
Reputation: Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute 
Solved Threads: 740
Team Colleague
Narue's Avatar
Narue Narue is offline Offline
Code Goddess

Re: ?: syntax problem

 
1
  #3
Aug 28th, 2008
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:
  1. String str = ( (String)result[i][1] != null ? (String)result[i][1] : "" );
Also, what type is result[i][1] such that a cast to String is required?
Last edited by Narue; Aug 28th, 2008 at 9:56 am.
I'm here to prove you wrong.
Reply With Quote Quick reply to this message  
Join Date: May 2008
Posts: 8
Reputation: Priya_Aggarwal is an unknown quantity at this point 
Solved Threads: 2
Priya_Aggarwal Priya_Aggarwal is offline Offline
Newbie Poster

Re: ?: syntax problem

 
0
  #4
Aug 28th, 2008
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.
Reply With Quote Quick reply to this message  
Join Date: Sep 2004
Posts: 7,752
Reputation: Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute 
Solved Threads: 740
Team Colleague
Narue's Avatar
Narue Narue is offline Offline
Code Goddess

Re: ?: syntax problem

 
1
  #5
Aug 28th, 2008
>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#.
I'm here to prove you wrong.
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC