How does Microsoft decide to make static / member methods in C #?

I noticed that in FCL there are many static methods that affect only one object, for example Array.Resize . What is the point of making them static?

+4
source share
1 answer

Instance methods can only change the properties of an object element. In your example, the Array.Resize method modifies the reference to the array, so it is static and takes a parameter by reference.

When you do this:

 int[] arr = ...; Array.Resize(ref arr, 10); 

the arr reference has been changed, which would be impossible by calling the method on arr .

Alternatively, in a language such as Java that does not support passing by reference, it will be declared to return a new array.

+3
source

Source: https://habr.com/ru/post/1397365/