Passing Objects By Reference or Value in C#

In C#, I have always thought that non-primitive variables were passed by reference and primitive values passed by value. So when passing to a method any non-primitive object, anything done to the object in the method would effect the object being passed. (C# 101 stuff) However, I have noticed that when I pass a System.Drawing.Image … Read more

Why use the ‘ref’ keyword when passing an object?

If I am passing an object to a method, why should I use the ref keyword? Isn’t this the default behaviour anyway? For example: class Program { static void Main(string[] args) { TestRef t = new TestRef(); t.Something = “Foo”; DoSomething(t); Console.WriteLine(t.Something); } static public void DoSomething(TestRef t) { t.Something = “Bar”; } } public … Read more

JavaScript by reference vs. by value [duplicate]

This question already has answers here: Is JavaScript a pass-by-reference or pass-by-value language? (33 answers) Closed 7 years ago. I’m looking for some good comprehensive reading material on when JavaScript passes something by value and when by reference and when modifying a passed item affects the value outside a function and when not. I’m also … Read more

Why should I use the keyword “final” on a method parameter in Java?

I can’t understand where the final keyword is really handy when it is used on method parameters. If we exclude the usage of anonymous classes, readability and intent declaration then it seems almost worthless to me. Enforcing that some data remains constant is not as strong as it seems. If the parameter is a primitive … Read more

Does JavaScript pass by reference? [duplicate]

This question already has answers here: Is JavaScript a pass-by-reference or pass-by-value language? (33 answers) Closed 2 years ago. Does JavaScript pass by references or pass by values? Here is an example from JavaScript: The Good Parts. I am very confused about the my parameter for the rectangle function. It is actually undefined, and redefined … Read more

What’s the difference between passing by reference vs. passing by value?

What is the difference between a parameter passed by reference a parameter passed by value? Could you give me some examples, please? 18 s 18 First and foremost, the “pass by value vs. pass by reference” distinction as defined in the CS theory is now obsolete because the technique originally defined as “pass by reference” … Read more

Is JavaScript a pass-by-reference or pass-by-value language?

The primitive types (number, string, etc.) are passed by value, but objects are unknown, because they can be both passed-by-value (in case we consider that a variable holding an object is in fact a reference to the object) and passed-by-reference (when we consider that the variable to the object holds the object itself). Although it … Read more