Click here to Skip to main content
14,869,895 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have an array of structures lets say

struct info
string a{get;set;}
string b{get;set;}
int c{get;set;}

And imagine that
info[] information;
is the array of information i have.

but i want to get just an array of the strings 'b'. What is the best way to do this/ is there a default way to handle this in c#. I need it as i wrote a useful function for compiling lists that works with strings.

I understand i could compile a list using foreach but this is a lot of code to use each time i want a list of items in the structure array.
Updated 18-Aug-13 8:05am

1 solution

string[] sa = information.Select(I => I.b).ToArray();

[edit]I hate typing code on a tablet... It autocorrected "sa" to "as"[/edit]
ridoy 18-Aug-13 14:45pm
very basic,but very useful too,+5 :)
Sergey Alexandrovich Kryukov 18-Aug-13 23:23pm
Nice solution, a 5.

During university time, we had a widely known rumor (urban legend, or rather a joke) about a journal editor who decided to "fix" the word "holes" (in solid-state physics) by changing it to the more literature-like word "openings" (a formal term in technical drawing). :-)


This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900