No wonder you code does not compile: if you're implementing the interface, you need to write implementation of every method and property. Probably, your own problem in writing matching declaration of all parameters.
It looks like you completely mixing up all possible combinations of references, pointers and address operators, managed and unmanaged, all together. You need to learn the difference between '*', '&' (unmanaged) and '^', '%' managed. But right now you can simply let rely on intellisense: before you write implementation, try to declare the interface reference to the object instance and write a call to its method. As soon as you type an open bracket intellisense will show you all what's expected.
In brief, you will see:
C#, value type passed by value:
(int a)
— C++/CLI: the same:
(int a)
C#, value type passed by ref:
(ref int a)
— C++/CLI: the same:
(int %a)
C#, reference type passed by value:
(string a)
— C++/CLI:
(string ^a)
C#, reference type passed by ref:
(ref string a)
— C++/CLI:
(string ^%a)
.
The last case is kind of stupid, but formally you can use it.
There is also
out
parameter in C#, which is similar to
ref
but always requires assignment in the method body. In C#, matching
ref
and
out
parameter modifiers are also used in the call, which makes C# syntax more fool-proof; but they are not used in C++/CLI.
Also, '%' is the analog of "address" operator used to get a reference from value of a reference type:
ref class Demo {
void Test() {
Demo demoVal;
Demo^ demoRef = %demoVal;
Demo^ demoHeapRef = gcnew Demo();
}
};
The value semantic with classes demonstrated on the example of
demoRef
is unique to C++/CLI. There is no such thing in C#, so all reference types are allocated on heap and only addressed by reference, so the variable declaration equivalent to
demoRef
is not possible (but possible with structures, which are value types).
Now you need to learn what all four cases mean semantically and only then try to understand the notation.
Trying different combination in hope it will compile and even run miraculously is… what's the politically correct expression?.. counterproductive…
Good luck,
—SA[EDIT] Answering follow-up Question after code samples are submitted: see another Answer.