Data type. Multi pair of values. How can I do this?

S

shapper

Hello,

I need to pass to a function a list of pairs of values.

For each item the first value is a string and the second value is an
Enum named Country.

For example, consider I need to pass 3 items:

"New York", Country.UnitedStates

"Paris", Country.France

"London", Country.England

What data type should I use create this?

And how can I access each item inside my function?

Thanks,

Miguel
 
L

Laurent Bugnion [MVP]

Hi,
Hello,

I need to pass to a function a list of pairs of values.

For each item the first value is a string and the second value is an
Enum named Country.

For example, consider I need to pass 3 items:

"New York", Country.UnitedStates

"Paris", Country.France

"London", Country.England

What data type should I use create this?

And how can I access each item inside my function?

Thanks,

Miguel

You could use a struct for this. Something like

public struct CityInfo
{
string name;
Country countryCode;
}

and then

CityInfo ny = new CityInfo();
ny.name = "New York";
ny.countryCode = Country.UnitedStates;

Structs are good when you need lightweight objects, like here for
logical grouping of attributes. Note however that contrarily to classes,
structs are value types, not reference types.

HTH,
Laurent
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top