Click here to Skip to main content
15,867,939 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I use a c# class and I must use this function in c++..so I must use a type of vector that can be exist in c++ and c#..

example c#:

public void Passa(List<int> integers, int b)
        {
            string v;

            integers = new List<int>();
            integers.Add(1);
            integers.Add(4);
            integers.Add(7);

            //Vector vector1 = new Vector(20, 30);
            // t =  { "Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat" };

            return;
}


but List<int> doesn't exist in c++..so what Must I use?

What I have tried:

I searched on google but I need a vector that I can use in c++ and c#
Posted
Updated 28-Feb-23 0:27am
v2
Comments
Shao Voon Wong 28-Feb-23 6:38am    
You can use C# List class in C++. See below.

System::Collections::Generic::List<int>^ myList = gcnew System::Collections::Generic::List<int>();

myList->Add(1);
myList->Add(2);
myList->Add(3);

1 solution

You should try some workaorund with a function in C# which has this signature.

C++
public passIntegers(int[] data, int count, int b) {
    List<int> integers = new List<int>();

    for( int i = 0; i < count; i++ ) {
        integers.add(data[i]);
    }
     
    Passa( integers, b);
}
Read my article Calling all station with example code which demonstrates the use of C++ with C#.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS


CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900