Convert one list to the other list type

I am doing this below - any better way to do this? converting one list to the other without creating new object?

DataContext c = new DataContext();
List<X> x=
context.X.Where(a => a.date>Datetime.Now>).ToList();            
        foreach(var a in x)
        {
            Y y= new Y();
            y.Name= a.Name;                
            c.Ys.InsertOnSubmit(y);
        }

        c.SubmitChanges();   

Answers


You might try:

var ys = context.X
                .Where(x => x.date > DateTime.Now)
                .Select(x => new Y { Name = x.Name });

c.Ys.InsertAllOnSubmit(ys);

Need Your Help

Maven Release-plugin "tag already exists" for nonexistant tag

git maven bamboo bitbucket-server svn2git

My setup: git-repository on an Atlassian Stash-server and Atlassian Bamboo.

Simple collsion not working to the left or top

collision

This should be a very easy question, basically I have two squares, and I'm trying to see if they overlap. So far I've figured out the right and bottom collisions, but I can't figure out collisions ...