bonzaster

Why there is a possible null reference warning

Sep 18th, 2014
186
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // JetBrains ReSharper 8.2.1
  2. // Build 8.2.1000.4556 on 2014-05-19T09:12:38
  3.  
  4.     public class Transformer
  5.     {
  6.         private void TransformElementBad(XElement field)
  7.         {
  8.             var format = string.Empty;
  9.  
  10.             if (field.Element("ViewFormatInfo") != null)
  11.                 format = field.Element("ViewFormatInfo").Value.Trim();
  12.  
  13.             Console.WriteLine(format);
  14.         }
  15.  
  16.         private void TransformElementGood(XElement field)
  17.         {
  18.             var format = string.Empty;
  19.  
  20.             var element = field.Element("ViewFormatInfo");
  21.             if (element != null)
  22.                 format = element.Value.Trim();
  23.  
  24.             Console.WriteLine(format);
  25.         }
  26.     }
RAW Paste Data