If I’m calling a method that uses a out or ref parameter why do you need to mark the parameters with out or ref when calling the method? i.e.
DateTime.TryParse(myDate, out dateLogged)
I had thought this was something to reduce ambiguity when operator overloading but if I create two methods like so:
void DoStuff(int x, out int y)
{
y = x + 1;
}
void DoStuff(int x, ref int y)
{
y = x + 1;
}
Then Visual Studio reports “Cannot define overloaded method ‘DoStuff’ because it differs from another method only on ref and out”, so I couldn’t do that anyway.
EDIT:
After a bit more research it seems that I would need to specify out or ref when calling a method if it there were two overloaded methods declared like this:
void DoStuff(int x, out int y)
void DoStuff(int x, int y)
It’s there so that you’re explicitly consenting to the possibility that the method you’re calling could modify the value of the variable itself. This is a C# language requirement; other languages like VB.NET do not require you to decorate the actual method call, just the method signature.