0

I have an unmanaged API function and below mentioned is it's equivalent c# code...

Myfunction(unit handle, int index, out bool flag,out int value, out string name); 

Here the variable index varies from 0 to 59. I am able to fetch the data individually. I mean I can pass value to the variable index from a TextBox and I am getting the corresponding outputs. But how to collect the values in an array fashion. Each time I don't want to give index input I simply want to display all the values in a ListBox... How to achieve this?

1 Answer 1

1

Before we start, this is not a multidimensional array. This is a simple linear array with one index.

Create a struct to hold the values for one item:

struct MyItem { bool flag; int value; string name; } 

Then have a function return an array of these:

MyItem[] GetItems() { MyItem[] result = new MyItem[ItemCount]; // Populate result return result; } 

Alternatively you might well store the data in a generic collection like List<MyItem>. Fundamentally the key is to creat a structure that can contain a single item, and then operate on collections of items.

Sign up to request clarification or add additional context in comments.

2 Comments

Ok understood. I have created a structure. Can you please let me understand how to call this into my function. Am not getting the result as I did some mistake. I have written like this listBox1.items.add(getitems());
You are going to have to write bespoke code to populate the list box. It's not going to understand your struct.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.