tags:

views:

48

answers:

2

I can't seem to figure this out...a little help please, thank you vm!

I have a generic collection of Features. Each Feature has a FeatureId and FeatureName. I need to pass the featureids into an IEnumerable<string>.

I thought I was close with this:

Listing.Features.ToArray().Cast<string>().AsEnumerable();

and even tried to 'MacGyver' it like

 var sb = new System.Text.StringBuilder();

 foreach (Feature f in Listing.Features)
 {
     sb.AppendFormat("{0}", f.FeatureId);
 }          
 SelectedFeatures = sb.ToString().ToArray();

SelectedFeatures being the IEnumerable<string>.

Am I getting close? I like the first attempt better as it's cleaner but am not picky anymore now that I'm stuck

A: 

If I understand what you need right, something like this:

var selectedFeatures = Listing.Features.Select(item=>item.FeatureId);

Or item.FeatureName as appropriate. The example above gives you an IEnumerable<T> where T==Item.FeatureId.GetType();

Andrew Barber
`.AsEnumerable()` is redundant - `.Select` returns IEnumerable
RPM1984
<facepalm> And I EDITED it to add that, too! heh
Andrew Barber
wow you are fast, i just posted my addendum...you are right on!! TY!
Bryant
I missed the `ToString()` in my answer! :)
Andrew Barber
A: 

I found an older code sample in another project that helped me...this is how I got it working:

Model.SelectedFeatures.Select(c => c.FeatureId.ToString())

Thank you anyways, HTH some1

Bryant