I have a C# program that calls a COM DLL that has a method called test
with two parameters: the first parameter is passed ByVal
, the second one is passed ByRef
.
This is what the COM DLL does:
Public Sub test(ByVal a As String, ByRef b As String)
a = "a"
b = "b"
End Sub
This is what C# program does:
test.Class1 x = new test.Class1();
string a = "1";
string b = "2";
x.test(a, ref b);
I notice that if I remove ref
keyword, the compiler doesn't advice me that I missed the ref
keyword and passes the parameter ByVal
. This can be a big problem if I miss the ref
keyword because I can't notice it until I know that it wants the ref
. Do you know why the compiler exhibits this behavior?