Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>If it ain't broke, don't fix it. Of course, if you have confidence in your unit tests, you can give it a whirl, but you shouldn't really go randomly changing code "just because".</p> <p>Of course - in some cases, simplifying code is a valid reason to make a change - but even something as innocent as switching to an auto-implemented property could break code that makes assumptions and uses reflection to update the fields directly. Or it could break serialization.</p> <p>Changing to "var" can actually give you a different (more specific) type, which might cause a different method overload to get selected, etc.</p> <p>So again; it comes down to your confidence in the unit tests.</p> <p>Other considerations:</p> <ul> <li>does the rest of the team understand the new syntax yet?</li> <li>does your project need to support C# 2.0 (for example, some open source projects might want to retain compatibility with C# 2.0).</li> </ul> <p>If neither of these are an issue, you should be OK to use the new features in new code... just be a <em>little</em> cautious before hitting "update all" on old code...</p> <p>Here's a trivial example of "var" as a breaking change:</p> <pre><code> static void Main() { using (TextReader reader = File.OpenText("foo.bar")) { // [HERE] Write(reader); } } static void Write(TextReader reader) { Console.Write(reader.ReadToEnd()); } static void Write(StreamReader reader) { throw new NotImplementedException(); } </code></pre> <p>Now switch to <code>var reader</code> on the line marked <code>[HERE]</code>...</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload