String.Join and Linq

S

shapper

Hello,

I have the following classes:

public class OptionPaper {
public Option Option { get; set; }
}

public class Option {
public Guid OptionID { get; set; }
public string Answer { get; set; }
}

I need to create a List<OptionPaper> and fill each OptionPaper >
Option.Name = Value from OptionsCSV.

OptionsCSV is a string that holds the Answers in CSV format:
OptionsCSV = "Answer 1, Answer 2, ..."

I have the following but I am having troubles in making this work:

List<OptionPaper>.Options = paper.OptionsCSV.Split(new char[]
{ ',' },

StringSplitOptions.RemoveEmptyEntries).
Select(a =>
new Option {
OptionID =
Guid.NewGuid(),
Answer =
a.Trim()
}).ToList();

I get the following error:
Cannot implicitly convert type
'System.Collections.Generic.List<Option>' to
'System.Collections.Generic.List<OptionPaper>'

How can I make this work?

Thanks,
Miguel
 
G

Göran Andersson

shapper said:
Hello,

I have the following classes:

public class OptionPaper {
public Option Option { get; set; }
}

public class Option {
public Guid OptionID { get; set; }
public string Answer { get; set; }
}

I need to create a List<OptionPaper> and fill each OptionPaper >
Option.Name = Value from OptionsCSV.

OptionsCSV is a string that holds the Answers in CSV format:
OptionsCSV = "Answer 1, Answer 2, ..."

I have the following but I am having troubles in making this work:

List<OptionPaper>.Options = paper.OptionsCSV.Split(new char[]
{ ',' },

StringSplitOptions.RemoveEmptyEntries).
Select(a =>

new OptionPaper { Option =
new Option {
OptionID =
Guid.NewGuid(),
Answer =
a.Trim()
}

}).ToList();

I get the following error:
Cannot implicitly convert type
'System.Collections.Generic.List<Option>' to
'System.Collections.Generic.List<OptionPaper>'

How can I make this work?

Thanks,
Miguel

You need to create an OptionPaper object that contains the Option
object, as I showed above.
 

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

Top