Connecting Tech Pros Worldwide Forums | Help | Site Map

Parse and Linq

shapper
Guest
 
Posts: n/a
#1: Sep 5 '08
Hello,

I am parsing a CSV string as follows:

var answers = CSVAnswers.Split(new char[] { ',' },
StringSplitOptions.RemoveEmptyEntries).Select(a =a.Trim()).ToList();

I would like to create a List<Answerwhich has 3 properties:
AnswerID, Answer, UpdatedDate

AnswerID is a Guid and I know how to get it.
Answer is taken from answers
UpdatedData is current date time and I also know how to get it

My question is if I can transform my expression to create directly the
list:

List<Answer= CSVAnswers ...

Thanks,
Miguel

Alberto Poblacion
Guest
 
Posts: n/a
#2: Sep 5 '08

re: Parse and Linq


"shapper" <mdmoura@gmail.comwrote in message
news:dd82f6fc-62e3-4c3c-85a6-87c16b66a806@x41g2000hsb.googlegroups.com...
Quote:
I am parsing a CSV string as follows:
>
var answers = CSVAnswers.Split(new char[] { ',' },
StringSplitOptions.RemoveEmptyEntries).Select(a =a.Trim()).ToList();
>
I would like to create a List<Answerwhich has 3 properties:
AnswerID, Answer, UpdatedDate
>
AnswerID is a Guid and I know how to get it.
Answer is taken from answers
UpdatedData is current date time and I also know how to get it
>
My question is if I can transform my expression to create directly the
list:
>
List<Answer= CSVAnswers ...

It's almost there. You can write your values in the select in a Linq
query:

var answers = from s in CSVAnswers.Split(new char[] { ',' },...etc...)
select new Answer(guid, s.Trim(), DateTime.Now);
List<Answerresult = answers.ToList();

Closed Thread


Similar C# / C Sharp bytes