Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Code Question
Message
From
01/09/2015 11:54:30
 
 
To
01/09/2015 07:27:53
John Baird
Coatesville, Pennsylvania, United States
General information
Forum:
ASP.NET
Category:
Other
Title:
Environment versions
Environment:
C# 4.0
OS:
Windows Server 2012
Network:
Windows 2008 Server
Database:
MS SQL Server
Application:
Web
Miscellaneous
Thread ID:
01623961
Message ID:
01624101
Views:
56
>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 ?
Previous
Reply
Map
View

Click here to load this message in the networking platform