Re: Shorthand conditional doesn't evaluate right
- From: Jon Skeet [C# MVP] <skeet@xxxxxxxxx>
- Date: Wed, 8 Mar 2006 07:42:25 -0000
John Bailo <jabailo@xxxxxxxxxx> 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 - <skeet@xxxxxxxxx>
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too
.
- References:
- Shorthand conditional doesn't evaluate right
- From: John Bailo
- Shorthand conditional doesn't evaluate right
- Prev by Date: RE: Create Form from Async-Callback
- Next by Date: RE: Encryption Article
- Previous by thread: Re: Shorthand conditional doesn't evaluate right
- Next by thread: RE: Calling C++ from C#
- Index(es):
Relevant Pages
|