Access to C ++ / CLI is overloaded [] Operator in C #

I have a C ++ / CLI class:

public ref class Foobar { public: // methods here etc.. // operator overload double operator[](int index); } 

How do I access Foobar from C # given what I tried:

 Foobar foo = new Foobar(); int i = foo[1]; 

and I get CS0021: Cannot apply indexing with [] to an expression of type 'Foobar'

+6
source share
1 answer

operator[] receives a special call in C ++ / CLI (and all .NET languages) - instead of being defined as an operator, it is defined as a property called default , called the default index property .

 public ref class Foobar { public: // methods here etc.. property double default[int]; } 
+6
source

Source: https://habr.com/ru/post/894692/


All Articles