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

What’s the difference between the ‘ref’ and ‘out’ keywords?

I’m creating a function where I need to pass an object so that it can be modified by the function. What is the difference between: public void myFunction(ref MyClass someClass) and public void myFunction(out MyClass someClass) Which should I use and why? 27 s 27 ref tells the compiler that the object is initialized before … Read more