How to write an If Condition having a single variable but multiple values.
Ex : 'Consider I have employee details filled in a data table
If (dt.Rows(0).Items("Id").ToString() = "548" Or dt.Rows(0).Items("Id").ToString() = "78787" Or dt.Rows(0).Items("Id").ToString() = "787" Or dt.Rows(0).Items("Id").ToString() = "11" Or dt.Rows(0).Items("Id").ToString() = "025" Or dt.Rows(0).Items("Id").ToString() = "568") Then
MessageBox.Show("INSIDE")
End if
How can I optimize this If condition?
OrElsewill short circuit theIfIdcolumn? I would guessInteger. In that case, one thing you could do is treat the values asIntegers. NEVER convert data that is not text toStringsunless you have to. In this case,CInt(dt.Rows(0)("Id")) = 548ordt.Rows(0).Field(Of Integer)("Id") = 548would be a start.