How do I do this using a Lambda expression?
foreach (var l in urllist)
{
l.Url = l.Url + "?id=" + client.id+ "&active=" + client.Active;
}
Don't use Linq to modify collections, use loops instead:
So this is the best approach (have a look at the UriBuilder
Class):
foreach (var l in urllist)
{
l.Url = string.Format("{0}?id={1}&active={2}", l.Url, client.id, client.Active);
}
You have to create a new collection otherwise what is less efficient than modifying the original collection:
urllist = urllist
.Select(l => {l.Url = string.Format("{0}?id={1}&active={2}", l.Url, client.id, client.Active; return l;})
.ToList();
If urllist
is a List<T>
you could also use the pre-linq .NET 2 method ForEach
:
urllist.ForEach(l => l.Url = string.Format("{0}?id={1}&active={2}", l.Url, client.id, client.Active));
이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.
침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제
몇 마디 만하겠습니다