I have a C # program that calls a COM library that has a method called testwith two parameters: the first parameter is passed ByVal, the second is passed ByRef.
This is what the COM library does:
Public Sub test(ByVal a As String, ByRef b As String)
a = "a"
b = "b"
End Sub
This is what the 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 delete the keyword ref, the compiler does not advise me to skip the keyword refand pass the parameter ByVal. This can be a big problem if I missed a keyword ref, because I can’t notice it until I know what it wants ref. Do you know why the compiler demonstrates this behavior?
source
share