Solved

C# Linq Remove All

Posted on 2016-08-09
2
60 Views
Last Modified: 2016-08-10
Is there a shorter way to write this so no  looping is involved?
                        for (int i = 0; i < data.Count; i++)
                        {
                            myObject.RemoveAll(x => x.Name == data[i].Name &&
                                                  x.Description == data[i].Description;
                        }

Open in new window

0
Comment
Question by:CipherIS
2 Comments
 
LVL 8

Accepted Solution

by:
Prakash Samariya earned 500 total points
ID: 41749937
Try linq code like below:
myObject.RemoveAll(
	x => data.Exists(
		y=> { 
			y.Name ==x.Name && y.Description==x.Description
		}
	)
);

Open in new window

0
 
LVL 1

Author Comment

by:CipherIS
ID: 41750968
Thanks that work with minor modification.
myObject.RemoveAll(
		x => data.Exists(
				y => y.Name == x.Name && 
				y.Description == x.Description
                  )
);

Open in new window

0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

This document covers how to connect to SQL Server and browse its contents.  It is meant for those new to Visual Studio and/or working with Microsoft SQL Server.  It is not a guide to building SQL Server database connections in your code.  This is mo…
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…

760 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

23 Experts available now in Live!

Get 1:1 Help Now