Skip to main content
edited body
Source Link
Max
  • 1.9k
  • 1
  • 13
  • 18

I personally prefer your 3rd example

Object addressParam = String.IsNullOrEmpty(Address.Text) ? (Object) DBNull.Value : (Object) Address.Text; comm.Parameters.AddWithValue("@Address", addressParam); 

It easily reads that you are evaluating and initializing your Object and directly aboveafter you're using your newly instantiated Object. It also doesn't take up as much space as your if-statements and it doesn't really slow you down when reading the code -> you see an Object being initialized and then used, and when needed you can always take an extra second to see what you're evaluating.

I personally prefer your 3rd example

Object addressParam = String.IsNullOrEmpty(Address.Text) ? (Object) DBNull.Value : (Object) Address.Text; comm.Parameters.AddWithValue("@Address", addressParam); 

It easily reads that you are evaluating and initializing your Object and directly above you're using your newly instantiated Object. It also doesn't take up as much space as your if-statements and it doesn't really slow you down when reading the code -> you see an Object being initialized and then used, and when needed you can always take an extra second to see what you're evaluating.

I personally prefer your 3rd example

Object addressParam = String.IsNullOrEmpty(Address.Text) ? (Object) DBNull.Value : (Object) Address.Text; comm.Parameters.AddWithValue("@Address", addressParam); 

It easily reads that you are evaluating and initializing your Object and directly after you're using your newly instantiated Object. It also doesn't take up as much space as your if-statements and it doesn't really slow you down when reading the code -> you see an Object being initialized and then used, and when needed you can always take an extra second to see what you're evaluating.

Source Link
Max
  • 1.9k
  • 1
  • 13
  • 18

I personally prefer your 3rd example

Object addressParam = String.IsNullOrEmpty(Address.Text) ? (Object) DBNull.Value : (Object) Address.Text; comm.Parameters.AddWithValue("@Address", addressParam); 

It easily reads that you are evaluating and initializing your Object and directly above you're using your newly instantiated Object. It also doesn't take up as much space as your if-statements and it doesn't really slow you down when reading the code -> you see an Object being initialized and then used, and when needed you can always take an extra second to see what you're evaluating.