Note that there are some explanatory texts on larger screens.

plurals
  1. POCode Analysis c# .NET CA1822
    primarykey
    data
    text
    <p>I run Code Analysis and got this message:</p> <blockquote> <p>CA1822 : Microsoft.Performance : The 'this' parameter (or 'Me' in Visual Basic) of 'CreateIntervalString(TimeSpan)' is never used. Mark the member as static (or Shared in Visual Basic) or use 'this'/'Me' in the method body or at least one property accessor, if appropriate.</p> </blockquote> <p>My code is:</p> <pre><code>private string CreateIntervalString(TimeSpan timeSpan) { return timeSpan.ToString(); } </code></pre> <p>as I understood, because <code>CreateIntervalString</code> function does not use any the members of the class, and only uses on the timeSpan input, VisualStudio recommends me to mark it as static.</p> <p>My Questions:</p> <ol> <li><strong>Why</strong> when I mark it as static, the performance is improved?</li> <li>My function is part of library that should be thread-safe, does marking method as static prevent this?</li> <li>I have additional private functions that use only its inputs, and does not use at any other members of the class, yet I don't get the same error for them.</li> </ol> <p>Thanks a lot! </p> <p>Examples:</p> <p>the following method provides an error:</p> <pre><code> private string CreateIntervalString(TimeSpan timeSpan) { return timeSpan.ToString(); } </code></pre> <p>and the following does not:</p> <pre><code> private DateTime ParseDateString(string dateTimeString) { // the years,monthe,days,hours,minutes and secondes found by the dateTimeString input return new DateTime(years, months, days, hours, minutes, secondes); } </code></pre>
    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. 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