How to access C# indexer in C++

  • Thread starter Thread starter Lei Jiang
  • Start date Start date
L

Lei Jiang

I have a C# class :

public class MyClass
{
public object this[int index]
{
}
}

In my C++ code, how to access this index method?

MyClass ^ myClass = gcnew MyClass();
myClass->????
 
Lei said:
I have a C# class :

public class MyClass
{
public object this[int index]
{
}
}

In my C++ code, how to access this index method?

MyClass ^ myClass = gcnew MyClass();
myClass->????



How do you access it in C#?






Regards,

Ioannis Vranos
 
In C#, just use myClass[index].

But I have found the answer now :

myClass->get_Item(index)


Ioannis Vranos said:
Lei said:
I have a C# class :

public class MyClass
{
public object this[int index]
{
}
}

In my C++ code, how to access this index method?

MyClass ^ myClass = gcnew MyClass();
myClass->????



How do you access it in C#?






Regards,

Ioannis Vranos
 
Lei said:
In C#, just use myClass[index].

But I have found the answer now :

myClass->get_Item(index)


Lei Jiang wrote:

I have a C# class :

public class MyClass
{
public object this[int index]
{
}
}



This is an indexed property so you can also use the [] operator in C++
the same way you do in C#.






Regards,

Ioannis Vranos
 
Lei said:
I have a C# class :

public class MyClass
{
public object this[int index]
{
}
}

In my C++ code, how to access this index method?

MyClass ^ myClass = gcnew MyClass();
myClass->????

The name of the indexed property is Item. C# uses that name by default, but
a few classes have a different name. In the new C++ syntax, you will be able
to access C# indexers with the same syntax (i.e. directly on the class
instance). Of course, C++ will still have named indexed properties if you
find them useful.
 
Back
Top