2

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?

Community
  • 1
  • 1
Colin
  • 41
  • 2

3 Answers3

1
If((supplierID > 0, (object)supplierID, DBNull.Value)
PaulB
  • 23,264
  • 14
  • 56
  • 75
1
cmd.Parameters.Add(New SqlParameter("@p2", (If((supplierID > 0), DirectCast(supplierID, Object), DBNull.Value))))
Vyasdev Meledath
  • 8,926
  • 20
  • 48
  • 68
0

You are describing a "ternary operator"

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

Adrian
  • 2,244
  • 18
  • 20
  • 2
    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 Oct 19 '10 at 11:56