EdSF - yes, that is the answer that i was looking for :) this was one of my versions, why this is happening.
It's sad - because i'm now stuck with slower function (or more code)...
when you posted your answer before edit, i haven't really understood what you've meant.
so i began to write console test application :)
Module Module1
Function f1() As String
Console.WriteLine("f1")
Return "return from f1"
End Function
Function f2() As String
Console.WriteLine("f2")
Return "return from f2"
End Function
Sub Main()
Dim str = ""
Console.WriteLine(If(str.Length > 0, f1, f2))
Console.WriteLine(IIf(str.Length > 0, f1, f2))
Console.WriteLine("-------")
Dim dec As Decimal?
dec = If(str.Length > 0, f1, Nothing)
If dec Is Nothing Then Console.WriteLine("Nothing") Else Console.WriteLine(dec)
Console.WriteLine("-------")
dec = IIf(str.Length > 0, f1, Nothing)
If dec Is Nothing Then Console.WriteLine("Nothing") Else Console.WriteLine(dec)
End Sub
End Module
anyway - thank you for clarification, i totally have thought, that IF and IIF have only one difference - speed.
P.S. it's interesting though, why IF returns nothing in this case: IF(str.length>0, nothing, nothing) and does not convert nothing to decimal 0D.
trolis
Member
102 Points
43 Posts
Re: Another bug ?? If() function this time...
Jun 06, 2011 08:54 PM|LINK
EdSF - yes, that is the answer that i was looking for :) this was one of my versions, why this is happening.
It's sad - because i'm now stuck with slower function (or more code)...
when you posted your answer before edit, i haven't really understood what you've meant.
so i began to write console test application :)
Module Module1 Function f1() As String Console.WriteLine("f1") Return "return from f1" End Function Function f2() As String Console.WriteLine("f2") Return "return from f2" End Function Sub Main() Dim str = "" Console.WriteLine(If(str.Length > 0, f1, f2)) Console.WriteLine(IIf(str.Length > 0, f1, f2)) Console.WriteLine("-------") Dim dec As Decimal? dec = If(str.Length > 0, f1, Nothing) If dec Is Nothing Then Console.WriteLine("Nothing") Else Console.WriteLine(dec) Console.WriteLine("-------") dec = IIf(str.Length > 0, f1, Nothing) If dec Is Nothing Then Console.WriteLine("Nothing") Else Console.WriteLine(dec) End Sub End Moduleanyway - thank you for clarification, i totally have thought, that IF and IIF have only one difference - speed.
P.S. it's interesting though, why IF returns nothing in this case: IF(str.length>0, nothing, nothing) and does not convert nothing to decimal 0D.