Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Code Question
Message
De
01/09/2015 11:54:30
 
 
À
01/09/2015 07:27:53
John Baird
Coatesville, Pennsylvanie, États-Unis
Information générale
Forum:
ASP.NET
Catégorie:
Autre
Titre:
Versions des environnements
Environment:
C# 4.0
OS:
Windows Server 2012
Network:
Windows 2008 Server
Database:
MS SQL Server
Application:
Web
Divers
Thread ID:
01623961
Message ID:
01624101
Vues:
57
>If you're worried about speed, shouldn't you drop the linq statement to list, and use the list in the foreach control. That way the linq is not executed for each iteration of the foreach.

Not really worried about speed but if you mean something like this:
List<TextBox> l = Controls.OfType<TextBox>().ToList();
            foreach (TextBox c in l)
            {
                c.CharacterCasing = CharacterCasing.Upper;
            }
then No, I don't see the point. It's creating a List of TextBoxes needlessly - better just to use the IEnumerable returned by 'OfType'



>>>A better LINQ way:
>>>
foreach (TextBox c in parentForm.Controls.OfType< TextBox>())
>>>            {
>>>                c.CharacterCasing = CharacterCasing.Upper;
>>>            }
Good. I'd forgotten about OfType(). Don't know if it's any faster because, internally, I think it does a 'is X' anyway ?
Précédent
Répondre
Fil
Voir

Click here to load this message in the networking platform