Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on Jul 15th, 2012  |  syntax: None  |  size: 0.60 KB  |  hits: 11  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. asp.net master property string, how to check in content page if string is empty
  2. public String SharedInfo
  3. {
  4.     get { return (String)Session["SharedInfo"]; }
  5.     set { Session["SharedInfo"] = value; }
  6. }
  7.        
  8. if (String.IsNullOrEmpty(Master.SharedInfo)) {
  9.     ...
  10. }
  11.        
  12. string s = null;
  13. int i = s.Length; // <-- Throws null reference exception
  14.        
  15. string s = "";
  16. int i = s.Length; // OK, i => 0
  17.        
  18. string s = "";
  19. Console.WriteLine(Object.ReferenceEquals(s, "")); // --> true
  20. Console.WriteLine(Object.ReferenceEquals(s, String.Empty)); // --> true
  21.        
  22. if (String.IsNullOrWhitespace(Master.SharedInfo)) {
  23.     ...
  24. }