My scenario :
I have an object, lets call it object1 which looks like this :
object1{
string commaSeparatedListOfIds;
DateTime time;
int passes;
...
irrelvant properties
...
}
What I wish to do is split commaSeparatedListOfIds for each id value, and save each one in it’s own object (object2), with the relevant other properties.
object2{
int id;
DateTime time;
int passes;
}
This duplicates information, but for the method I want to write any other solution will be horrifically messy.
What I have tried is :
List<object2> newObjects = new List<object2>(object1.commaSeparatedListOfIds.Split(',').Select(
new object2{
id int.Parse,
time = object1.time
passes = object1.passes
}).ToList<object2>());
but this will not build.
Can anyone help me do what I wish as elegantly as possible please ? I realise it would be possible with two loops and some horrible code, but I know there’s a nice looking solution out there somewhere! 🙂
I believe you want something like: