Note that there are some explanatory texts on larger screens.

plurals
  1. POPerformance of static methods vs instance methods
    primarykey
    data
    text
    <p>My question is relating to the performance characteristics of static methods vs instance methods and their scalability. Assume for this scenario that all class definitions are in a single assembly and that multiple discrete pointer types are required.</p> <p>Consider:</p> <pre><code>public sealed class InstanceClass { public int DoOperation1(string input) { // Some operation. } public int DoOperation2(string input) { // Some operation. } // … more instance methods. } public static class StaticClass { public static int DoOperation1(string input) { // Some operation. } public static int DoOperation2(string input) { // Some operation. } // … more static methods. } </code></pre> <p>The above classes represent a helper style pattern.</p> <p>In an instance class, resolving the instance method take a moment to do as oppose to StaticClass.</p> <p>My questions are:</p> <ol> <li><p>When keeping state is not a concern (no fields or properties are required), is it always better to use a static class?</p></li> <li><p>Where there is a considerable number of these static class definitions (say 100 for example, with a number of static methods each) will this affect execution performance or memory consumption negatively as compared with the same number of instance class definitions?</p></li> <li><p>When another method within the same instance class is called, does the instance resolution still occur? For example using the [this] keyword like <code>this.DoOperation2("abc")</code> from within <code>DoOperation1</code> of the same instance.</p></li> </ol>
    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.
 

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