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

  • Thread starter Thread starter shapper
  • Start date Start date
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
 
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
 
Back
Top