I’ve noticed that there are many static methods in FCL that affect only single object, for example Array.Resize. What’s the point making them static?
I’ve noticed that there are many static methods in FCL that affect only single
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Instance methods can only modify the member properties of an object. In your example of
Array.Resize, the method modifies the array reference itself, which is why it is static and takes the parameter by reference.When you do this:
the
arrreference itself is modified, which would not be possible by calling a method onarr.Alternatively, in a language such as Java which does not support passing by reference, it would be declared to return the new array.