开发者

Access C++/CLI Overloaded [] Operator in C#

开发者 https://www.devze.com 2023-03-27 02:43 出处:网络
I have a C++/CLI class: public ref class Foobar { public: // methods here etc.. // operator overload double operator[](int index);

I have a C++/CLI class:

public ref class Foobar
{
    public:
        // methods here etc..

        // operator overload
        double operator[](int index);
}

How do I ac开发者_如何学Ccess Foobar from C# given that I've tried:

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

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


operator[] gets special treatment in C++/CLI (and all .NET languages) – rather than being defined as an operator, it's defined as a property named default, known as the default index property.

public ref class Foobar
{
public:
    // methods here etc..

    property double default[int];
}
0

精彩评论

暂无评论...
验证码 换一张
取 消