code_junkie

variable.ToString() vs. Convert.ToString(variable)

Nov 12th, 2011
58
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.38 KB | None | 0 0
  1. int someValue = 4;
  2.  
  3. // You can do this
  4. txtSomeValue.Text = someValue.ToString();
  5.  
  6. // Or this...
  7. txtSomeValue.Text = Convert.ToString(someValue);
  8.  
  9. //This will set the variable test to null:
  10. string test = Convert.ToString(ConfigurationSettings.AppSettings["Missing.Value"]);
  11.  
  12. //This will throw an exception:
  13. string test = ConfigurationSettings.AppSettings["Missing.Value"].ToString();
Add Comment
Please, Sign In to add comment