VB IIF in C#

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hi All

Learning C# - what is the equivalent in C# for the following statement

al.CompanyID = IIf(IsDBNull(d("CompanyID")), "", d("CompanyID")

I don't see anything in C# that provides for this one line type of syntax. Seems I have to use a If-else block for each in C#

True or am I missing something

Appreciate anyone that can clear this up for me

thanks...Bobb
 
Like so (called the conditional operator or conditional ternary operator):

bool booleanStatement = true;
string resultValue = booleanStatement ? "The true part" : "The false part;
// set to "The true part"

--
C#, .NET and Complex Adaptive Systems:
http://blogs.geekdojo.net/Richard
Bobbo said:
Hi All,

Learning C# - what is the equivalent in C# for the following statement?

al.CompanyID = IIf(IsDBNull(d("CompanyID")), "", d("CompanyID"))


I don't see anything in C# that provides for this one line type of syntax.
Seems I have to use a If-else block for each in C#.
 
Hi,

Take note that there is a slight difference.
I am not sure but I think that Iif evaluates both (true and false) parts,
while ?: evaluates only target part.
 
Miha,
Take note that there is a slight difference.
Slight, there is a major difference! ;-)

IIF is a function that accepts object parameters & returns an object. So yes
all the parameters are evaluated.

BTW: It's in the Microsoft.VisualBasic.Interaction class (Module/static
class), in the Microsoft.VisualBasic assembly.

Hope this helps
Jay
 
Back
Top