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?
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.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.