Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > Data type. Multi pair of values. How can I do this?

Reply
Thread Tools

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

 
 
shapper
Guest
Posts: n/a
 
      02-24-2007
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

 
Reply With Quote
 
 
 
 
Mark Rae
Guest
Posts: n/a
 
      02-24-2007
"shapper" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed) oups.com...

> What data type should I use create this?
>
> And how can I access each item inside my function?


http://msdn2.microsoft.com/en-us/library/xfhwa508.aspx


 
Reply With Quote
 
 
 
 
Laurent Bugnion [MVP]
Guest
Posts: n/a
 
      02-24-2007
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
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Re: How include a large array? Edward A. Falk C Programming 1 04-04-2013 08:07 PM
Buffer pair for lexical analysis of raw binary data Angus Rodgers Python 3 06-28-2009 04:26 PM
key-value pair , with key as primitive data type studentoflife77@gmail.com Java 1 11-16-2007 01:10 AM



Advertisments