Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Setting properties in Generic list
Message
From
13/11/2014 14:54:05
 
 
General information
Forum:
ASP.NET
Category:
Other
Environment versions
Environment:
C# 5.0
OS:
Windows 7
Network:
SAMBA Server
Database:
MS SQL Server
Application:
Desktop
Miscellaneous
Thread ID:
01610922
Message ID:
01610937
Views:
31
>>Hi All, is it possible in a "Linq type way" to set properties of class instances which are in a IList ? , for example I have a list of names and addresses in a list and if there are some that share a certain residential area code (e.g. UK ) I would like to set a property in the instances, hope this makes sense.
>
>Closest you can get is probably something like:
foreach(Info i in list.Where(x=>x.Postcode.StartsWith="HR"))
>            {
>                i.SomeProperty = true;
>            }
List does have a foreach method (http://msdn.microsoft.com/en-us/library/bwabdf9z%28v=vs.110%29.aspx), but its not really recommended (http://blogs.msdn.com/b/ericlippert/archive/2009/05/18/foreach-vs-foreach.aspx). There is also a parallel foreach (http://msdn.microsoft.com/en-us/library/dd992001%28v=vs.110%29.aspx) you could use if setting the value has no side effects.
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform