473,506 Members | 9,749 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Shorthand conditional doesn't evaluate right


string s = "ABC";

Debug.WriteLine(

s.Length>5?"greater":"lesser"

);
The compiler reports:

Operator '>' cannot be applied to operands of type 'string' and 'int'

Isn't Length an int ?

Mar 7 '06 #1
2 1144
Works for me.... Is that the exact line you are trying to compile? Usually
the "?" conditional complains about lines such as

s.Length>5?"greater":8


"John Bailo" <ja*****@texeme.com> wrote in message
news:1M********************@speakeasy.net...

string s = "ABC";

Debug.WriteLine(

s.Length>5?"greater":"lesser"

);
The compiler reports:

Operator '>' cannot be applied to operands of type 'string' and 'int'

Isn't Length an int ?

Mar 7 '06 #2
John Bailo <ja*****@texeme.com> wrote:

string s = "ABC";

Debug.WriteLine(

s.Length>5?"greater":"lesser"

);

The compiler reports:

Operator '>' cannot be applied to operands of type 'string' and 'int'

Isn't Length an int ?


I don't think that's your real code. Could you post a short but
complete program which demonstrates the problem?

See http://www.pobox.com/~skeet/csharp/complete.html for details of
what I mean by that.

Here's an example showing your code working fine:

using System;

class Test
{
static void Main()
{
string s = "ABC";
Console.WriteLine (s.Length>5 ? "greater":"lesser");
}
}

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too
Mar 8 '06 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

8
2262
by: neblackcat | last post by:
Would anyone like to comment on the following idea? I was just going to offer it as a new PEP until it was suggested that I post it here for comment & consideration against PEP 308. I'm far...
4
4447
by: TheKeith | last post by:
I just wrote the following script for something I'm working on: ---------------------------------------------------------------------------- ------------------- <html> <head> <script...
9
12876
by: Andy | last post by:
I'm a beginning student of CSS and the shorthand order for margins, etc. raised an eyebrow. The clockwise order is what bothers me: p.margin {margin: cm cm cm cm} I think the order should...
2
1039
by: Bill Davidson | last post by:
Hello there, I need help on understanding part of the macro below: #define MY_MACRO( OP, RESULT ) \ ( (RESULT = (OP)) != 0 ? (errno = RESULT, -1) : 0 ) What I do not understand is how is...
34
3160
by: BQ | last post by:
Hello Is there a way to declare 'FUNCT' via a define so that if its parameter x, a constant, is greater than 35, it returns 56, if not, 20. I would like that at compile time, not at run time. ...
23
449
by: Wayne Wengert | last post by:
In a Datagrid I have a field (<td>) in which I want to display a link if a database field is still Null but I want to display a blank (&nbsp;) if that DB field has a value. If I try to put the...
11
5851
by: volcs0 | last post by:
I've done this in Scheme, but I'm not sure I can in Python. I want the equivalent of this: if a == "yes": answer = "go ahead" else: answer = "stop" in this more compact form:
5
1690
by: A.M | last post by:
Hi, I am using Python 2.4. I read the PEP 308 at: http://www.python.org/dev/peps/pep-0308/
5
2890
by: paulo | last post by:
Can anyone please tell me how the C language interprets the following code: #include <stdio.h> int main(void) { int a = 1; int b = 10; int x = 3;
0
7220
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7105
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7308
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
7371
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
7023
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
7479
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
5617
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
4702
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
1534
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.