List conversion

S

shapper

Hello,

I am using the following to convert a CSV String to a List:

updated = paper.Tags.Split(',').Select(p => p.Trim()).ToList();

But I want to place the values in the Name property of a List of Tag
(Tag is a class with 2 properties: ID and Name)

I tried the following:

List<Tag> updated = paper.Tags.Split(',').Select(p =>
p.Trim()).ToList();

But of course I need to place this in each Tag.Name ...

Any idea?

Thanks,
Miguel
 
A

Arne Vajhøj

shapper said:
I am using the following to convert a CSV String to a List:

updated = paper.Tags.Split(',').Select(p => p.Trim()).ToList();

But I want to place the values in the Name property of a List of Tag
(Tag is a class with 2 properties: ID and Name)

I tried the following:

List<Tag> updated = paper.Tags.Split(',').Select(p =>
p.Trim()).ToList();

But of course I need to place this in each Tag.Name ...

Try with a new inside Select.

Arne
 
T

Tim Jarvis

shapper said:
List<Tag> updated = paper.Tags.Split(',').Select(p =>
p.Trim()).ToList();

But of course I need to place this in each Tag.Name ...

Any idea?

Thanks,
Miguel

Hi Miguel,

List<Tag> updated = (from s in paper.tags.Split(',')
select new Tag()
{
Name = s.Trim()
}).ToList();

Regards Tim.

--
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads

Create List in Linq 4
Linq Query. Please, help. Going crazy ... 1
List to CSV 3
(Collection) 1
Linq. Select 2
Linq.How to complete this query? 2
Linq > Group 2
ToString and FromString 10

Top