is there a way to use shorthand to do something like this?
If Not txtBookTitle.Text = String.Empty Then
objBook.DisplayName = txtBookTitle.Text
End If
is there a way to use shorthand to do something like this?
If Not txtBookTitle.Text = String.Empty Then
objBook.DisplayName = txtBookTitle.Text
End If
objBook.DisplayName = If(Not (txtBookTitle.Text = String.Empty), txtBookTitle.Text, objBook.DisplayName)
There are two version of the if statement shorthand. Either If(expression, true part, false part) or If(expression, false part)
objBook.DisplayName = If(String.IsNullOrEmpty(txtBookTitle.Text), txtBookTitle.Text)
Following code is similar to your three line of code:
objBook.DisplayName = IIF(String.IsNullorEmpty(txtBookTitle.Text),objBook.DisplayName, txtBookTitle.Text)
This is the shortest version (81 character):
If txtBookTitle.Text <> String.Empty Then objBook.DisplayName = txtBookTitle.Text
And I would prefer this for debug-ability. Also easily convertible to C#.