I'd say: do not use
Iif[
^] function, which returns one of two objects, depending on the evaluation of an expression. Why? There is much, much better programming practice to use lambda expressions:
Dim boolVal as Boolean = False
Dim result = Function(x As Boolean) As String
Dim sRetVal as String = "yes"
Select Case x
Case true
sRetVal = "yes"
Case False
sRetVal = "no"
End Select
Return sRetVal
End Function
Console.WriteLine("The result is: {0}", result(boolval))
Above example is very simple. You may say that it's much easier to use
iif
or even
if
function (as is mentioned in answers to this question). It's true, but using lambda expressions is more flexible, because provides a way to create custom function that verifies condition and returns result as you define it.
For further information, please see:
How to: Create a Lambda Expression (Visual Basic)[
^]
By The Way, C# is more powerfull! Above Vb.Net code we can write as:
string result = boolVal==true ? "yes" : "no";
Console.WriteLine("The result is: {0}, result);
Cheers,
Maciej