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. Advertisements

  2. shapper

    Mark Rae Guest

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

  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. Advertisements

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. luna
    Replies:
    1
    Views:
    7,046
  2. Richard Dixson
    Replies:
    1
    Views:
    745
    Joe Fallon
    May 18, 2004
  3. Replies:
    2
    Views:
    418
    Ian Collins
    Oct 25, 2006
  4. Replies:
    1
    Views:
    791
    Daniel Pitts
    Nov 16, 2007
  5. arnuld

    can not print a <pair>

    arnuld, Nov 22, 2007, in forum: C++
    Replies:
    1
    Views:
    276
    arnuld
    Nov 22, 2007
  6. boempire

    Problem with Vector<pair<type,type>>

    boempire, Mar 30, 2008, in forum: C Programming
    Replies:
    1
    Views:
    14,175
    sjord010
    May 4, 2008
  7. Angus Rodgers
    Replies:
    3
    Views:
    1,402
  8. V.Subramanian, India
    Replies:
    6
    Views:
    692
Loading...