473,385 Members | 1,720 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

String.Join and Linq

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<OptionPaperand 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
Oct 4 '08 #1
1 2089
shapper wrote:
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<OptionPaperand 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.

--
Göran Andersson
_____
http://www.guffa.com
Oct 5 '08 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: shapper | last post by:
Hello, I have 2 tables: Aid, Aname ... Bid, Aid, Bname ... I need to get the records in B given a Bname and a Aname. I think I should use Inner Join. I wrote the following code:
9
by: gs | last post by:
is there any built in function or dotnet framework(version 2) to merge a generic list of string into one string with each element delimited by specified delimiting string? or do I have to roll...
0
by: john | last post by:
I get the following error on this Join Statement, but I thought the idea of a LINQ Join is bring together different Data Context, the Intellisene shows me both tables as a Result; any help is...
5
by: shapper | last post by:
Hello, I have the following LINQ query: PostPaper paper = (from p in database.Posts where p.PostID == id select new PostPaper { Post = p, Tags = new List<Tag>( from pt in database.PostTags
4
by: shapper | last post by:
Hello, I have a list named Form which is a List(Of Tag) where Tag is an object with two properties: ID and Name. I want to define a variable named Check that: 1. Is True if all Tags in Form...
0
by: shapper | last post by:
Hello, I have three tables: Posts, Tags and PostsTags which relates Tags to Posts. I created the dbml file. I have a List(Of Tag) named "form" with the Name defined for each tag. I need to...
2
by: Gilbert Tordeur | last post by:
Hello, I work with VB2008 and SQL Server 2000. I would like to make a JOIN between to SQL tables that are stored on different servers. How should I write the LINQ statement(s) ? Thank you...
1
by: Dean Slindee | last post by:
VS2008, .NetFramework 3.5 SP1: I have built a LINQ data access layer project. When the LINQ data context was built over an existing SQL2005 database, the connection string for that database was...
0
by: dlouche | last post by:
I have a method that contains the linq query: var query = from c in db.Categories join pc in db.ProductsToCategories on c.ID equals pc.CategoryID where...
0
by: Jay Douglas | last post by:
Hello, I've found some posts on creating dynamic WHERE clauses in LINQ to SQL using predicate builders and extending lamda expressions. One issue with these posts is all the examples only use a...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.