Solved

C# Linq Remove All

Posted on 2016-08-09
2
99 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 9

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

Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

For those of you who don't follow the news, or just happen to live under rocks, Microsoft Research released a beta SDK (http://www.microsoft.com/en-us/download/details.aspx?id=27876) for the Xbox 360 Kinect. If you don't know what a Kinect is (http:…
This article shows how to deploy dynamic backgrounds to computers depending on the aspect ratio of display
Microsoft Active Directory, the widely used IT infrastructure, is known for its high risk of credential theft. The best way to test your Active Directory’s vulnerabilities to pass-the-ticket, pass-the-hash, privilege escalation, and malware attacks …

837 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