![]() |
IOBit Software
|
|
|
||||||
| Programming Place to discuss programming including HTML, Java, C++, MySQL and others. |
![]() |
|
|
Thread Tools | Display Modes |
|
|
|
#1
|
|||
|
|||
|
I have this foreach statement to filter from my list of address (addressinfo) the ones that doesnt have the flag deleted on DB.
var accountSvc = new AccountSvc(); var personInfo = accountSvc.GetProfileInfo(AccountPhone); var addressInfo = accountSvc.GetPersonAddresses(personInfo.Id); if (repAddresses != null) foreach (var add in addressInfo) if (add.Deleted == false || add.Deleted == null) { var personSvc = new Shared.Core.Person.PersonSvc(); var address = personSvc.GetAddressProfile(add.AddressId); // addressInfo = address; } repAddresses.DataSource = addressInfo; repAddresses.DataBind(); if I do addessInfo = address I will get only the last address in loop, how can I save each address that go thru the loop and return them all. Thanks |
| Sponsored links |
|
|
|
#2
|
||||
|
||||
|
You can use Linq/Lambda Expressions (if you are using .NET 4.0)
Code:
var activeAddresses = addressInfo.Where(add => add.Deleted == false || add.Deleted == null)
foreach (add in activeAddresses)
{
// Do Processing on the addresses
}
Code:
List<AddressInfoType> activeAddresses = new List<AddressInfoType>(); //*
foreach (var add in addressInfo)
{
if (add.Deleted == false || add.Deleted == null)
{
var personSvc = new Shared.Core.Person.PersonSvc();
var address = personSvc.GetAddressProfile(add.AddressId);
activeAddresses.Add(address);
}
}
__________________
"I cannot undertake to lay my finger on that article of the Constitution which granted a right to Congress of expending, on the objects of benevolence, the money of their constituents." -- James Madison (1751-1836), Father of the Constitution for the USA, 4th US President _________________________ AMD Athlon 64 3800+ ABIT KN8 SLI 2 Gb (2x1Gb) PC 3200 Cas 2 Corsair XMS RAM 2x120Gb WD w/ 8Mb cache (RAID 0) eVGA GeForce 7900GT 256MB |
| The Following User Says Thank You to Wyatt_Earp For This Useful Post: | ||
jcast (05-30-12) | ||
|
#3
|
|||
|
|||
|
Many Thanks to Wyatt_Earp
|
|
#4
|
|||
|
|||
|
The foreach loop is useful for traversing each items in an array or a collection of items and displayed one by one.
for each syntax is foreach(variable type in collection){ // code block } source : http://csharp.net-informations.com/s...p-for-loop.htm legard. |
![]() |
| Tags |
| csharp |
| Thread Tools | |
| Display Modes | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Out of the loop | DxH | Hardware | 6 | 04-07-11 19:56 |
| VBA loop | Black_Bean | Programming | 0 | 11-09-10 17:09 |
| Log in/log off loop | epicfail13 | Malware Removal | 4 | 06-12-09 14:28 |
| Log in/log off loop | epicfail13 | Software | 8 | 06-06-09 21:07 |
| do..while loop question - help newbie please | bobjohnson | Programming | 1 | 07-05-04 19:26 |