Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>The most time you inherit of <code>System.Array</code> is using a single dimension array. like:</p> <pre><code>int[] a1 = new int[2]; </code></pre> <p>When you define <code>int[]</code> this implicitly derived from <code>System.Array</code> type like @Sergey Rybalkin says. In this case the method <code>IndexOf</code> would surely be best implemented as a instance method and not as static method. </p> <p>But there is another types that inherit from System.Array like mult dimension arrays. In this case (mult dimension) the method <code>IndexOf</code> does not make sense.</p> <p>Test this:</p> <pre><code>int[,] arr = new int[2, 2]; arr[0, 0] = 3; arr[1, 0] = 4; arr[0, 1] = 5; arr[1, 1] = 6; Array.IndexOf(arr, 4); </code></pre> <p>The last like throws a RankException with the message <code>"Only single dimension arrays are supported here."</code></p> <p>Perhaps, and most probably, because of that this method is implemented as static.</p> <p>...</p> <p>About the comment <code>Is there a main principle behind the decision, whether to make a method static or not?</code></p> <p>There is, and the principle is quite simple. The instance method represents a action or behavior of a object. The static method is a function of the system that is logic related with the class, or in some cases a method you want to call without creating an instance of the class.</p> <p>Think in <code>System.Math</code> class how mess will be if you need instance math every time you want call a method like <code>Sqrt</code>or <code>Pow</code>?</p> <p>The final example I will give to you is the <code>System.Text.RegularExpressions.Regex</code> class. This class have a <code>Match</code> method implemented as instance and an overload implemented as static.</p> <p>Each one is used in a diferent context. The instance is used when you use the same pattern multiple times. The static when you use the pattern a unique time in your 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. This table or related slice is empty.
    1. VO
      singulars
      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