I am looking to write a function like
ref String TestIt( int index ) { return this.TestArray[index]; };
so that I could write code like:
MyClass.TestIt(0) = 'Hello World';
My goal is to mimic this c++ declaration
CString& MyClass::Data( UINT index);
By Reference I am referring to the c++ term the Address of the variable.
in other words after my call to TestIT(0) TestArray[0] would contain ‘Hello World’.
EDIT I can’t use an indexer because my goal is to convert a .cpp file to c# on an ongoing basis. The closer I can mimic this c++ code, the less of a converter I have to write.
To do this you need to write a setter property. Unfortunately, setters can’t take further arguments in C# so you won’t be able to write this code 1:1 in C#. The closest you can get is a nested class with a default property:
You can use it like this:
By the way, since this is so much effort, you probably don’t want to do this. Also, it doesn’t feel very C#-y. The useless indiretion through the nested class here isn’t something you’ll see very often.