Equivalent of For Loop in LINQ

.net, c#, c#-4.0, linq

Solution

`Select` is the equivalent in this case:

playerViewModelList = playerData.Select(dataTeam => new PlayersViewModel
                                        {
                                            PicPath = dataTeam.Tied.ToString(),
                                            PlayerID = (int)dataTeam.ID,
                                            PlayerName = dataTeam.TeamName
                                        }).ToList();

Of course, this assumes `playerViewModelList` is a `List<PlayersViewModel>` or something similar. If you can't overwrite `playerViewModelList`, just stick with the `foreach` loop.

Problem

I am new to LINQ. `playerData` is a `list<DataAccess.Team>` and I want to initialize another list of `playerViewModelList` with the data from `playerData`. I tried `foreach`. ``` foreach (DataAccess.Team dataTeam in playerData) { playerViewModelList.Add(new PlayersViewModel { PicPath = dataTeam.Tied.ToString(), PlayerID = (int)dataTeam.ID, PlayerName = dataTeam.TeamName }); } ``` Is it possible to achieve the same thing using LINQ?

Original source