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

Discussion in 'ASP .Net' started by shapper, Feb 24, 2007.

  1. shapper

    shapper Guest

    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
     
    shapper, Feb 24, 2007
    #1
    1. Advertising

  2. shapper

    Mark Rae Guest

    Mark Rae, Feb 24, 2007
    #2
    1. Advertising

  3. Hi,

    shapper wrote:
    > 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
    --
    Laurent Bugnion [MVP ASP.NET]
    Software engineering, Blog: http://www.galasoft-LB.ch
    PhotoAlbum: http://www.galasoft-LB.ch/pictures
    Support children in Calcutta: http://www.calcutta-espoir.ch
     
    Laurent Bugnion [MVP], Feb 24, 2007
    #3
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Replies:
    2
    Views:
    345
    Ian Collins
    Oct 25, 2006
  2. Replies:
    1
    Views:
    608
    Daniel Pitts
    Nov 16, 2007
  3. boempire

    Problem with Vector<pair<type,type>>

    boempire, Mar 30, 2008, in forum: C Programming
    Replies:
    1
    Views:
    13,338
    sjord010
    May 4, 2008
  4. Angus Rodgers
    Replies:
    3
    Views:
    1,227
  5. V.Subramanian, India
    Replies:
    6
    Views:
    523
Loading...

Share This Page