I have the following code, I want to use Linq, any possible ??
I have one list of users, and I need generate other list.
any help ? thanks in advance, greetings
SortedList<ClaveUsuarioPersonal, UsuarioRe> users = new SortedList<ClaveUsuarioPersonal, UsuarioRe>();
if (this.UsuarioRe.UsuarioSar != null)
{
foreach (DC.AccesosUsuario var in this.UsuarioRe.UsuarioSar.ListaAccesos)
{
if (var != null && var.Aprobado.Value)
{
UsuarioRe usuario = UserContextBLL.ObtenerUsuarioRe(var.Login);
if(usuario!=null && usuario.UsuarioAire!=null)
{
if (!usuario.UsuarioAire.Empresa.HasValue)
{
Log.Trace(Utility.LogCategory, "No existe empresa para el usuario de Aire " + usuario.UsuarioAire.Login);
}
else
{
ClaveUsuarioPersonal clave = new ClaveUsuarioPersonal(Convert.ToInt32(usuario.UsuarioAire.Empresa.Value), usuario.UsuarioAire.Login);
users.Add(clave, usuario);
}
}
}
}
}
return users;
try installing Resharper 5.0 Nightly Build.
It has a lot of features to convert for/foreach to linq statements. It might be helpful for those who want to learn LINQ.
More info on these features here.
Edit: Jetbrains released Resharper 5.0 Beta a few days ago. Seems to be more stable than the nightly builds.