tags:

views:

71

answers:

4

Possible Duplicate:
Is there a conditional ternary operator in VB.NET?

C# has a shortcut like this:

cmd.Parameters.Add(new SqlParameter("@p2", ((supplierID > 0) ? (object)supplierID : DBNull.Value)));

Just curious if VB .Net has something like that too?

A: 

You are describing a "ternary operator"

http://blog.dmbcllc.com/2007/11/29/the-ternary-operator-in-vbnet/

Adrian
Yes, it's a ternary operator, but it's actually called the **IF** operator. http://blogs.msdn.com/b/vbteam/archive/2008/03/11/if-operator-a-new-and-improved-iif-sophia-salim.aspx
LukeH
+2  A: 

http://stackoverflow.com/questions/576431/is-there-a-conditional-ternary-operator-in-vb-net

ohadsc
Should be a comment rather than an answer though.
ho1
Magnifique. Now I know to search for "ternary" keyword. But StackOverflow is da bomb with its fast reply.
Colin
+1  A: 
If((supplierID > 0, (object)supplierID, DBNull.Value)
PaulB
+1  A: 
cmd.Parameters.Add(New SqlParameter("@p2", (If((supplierID > 0), DirectCast(supplierID, Object), DBNull.Value))))
Vyas