C# .NET - iif statement in c# - Asked By Seema Nandi on 25-Feb-06 02:30 AM

what the equivalent of vb's iif statement in c#.net

see the equivalent - Asked By Venkat K on 25-Feb-06 04:19 AM

code
[CODE]
Dim str As String = "This is some data"
Dim str1 As String = IIf(str.Trim = String.Empty, "Hi", "Bye")
[/CODE]

in c#
[CODE]
string str = "MyData";
string str1 = (str.Trim() = string.Empty ? "Hi" : "Bye");
[/CODE]

Convert IIF VB to C# - va gj replied to Seema Nandi on 09-Nov-06 04:45 PM

Does enyone knows how realy do this?


for example: 
Curvalue = IIf(Curvalue1 > Curvalue2, Curvalue2, Curvalue1)

equivalent of vb's iif statement in c#.net - kulwant kulwant replied to Seema Nandi on 12-Mar-08 02:44 AM

 C# has what is known as the "tertiary operator", which works like this:

booleanExpression ? trueValue : falseValue;

In practise, this is used like this:

int count = GetItemCount();

// Change display text depending on count
string itemText = count > 1 ? "items" : "item";

Console.WriteLine("Found {0} {1}", count, itemText);

IIF equivalent in C#.net - Divya K G replied to Venkat K on 11-May-09 04:59 AM
string oldString = "hi";
string newString = (oldString.Trim() == ""? ".." : oldString);