Solved

C# Linq Remove All

Posted on 2016-08-09
2
145 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 10

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

Is Your DevOps Pipeline Leaking?

Is your CI/CD pipeline a hodge-podge of randomly connected tools? You’ve likely got a tool to fix one problem & then a different tool to fix another, resulting in a cluster of tools with overlapping functionality. Learn how to optimize your pipeline with Gartner's recommendations

Question has a verified solution.

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

We all know that functional code is the leg that any good program stands on when it comes right down to it, however, if your program lacks a good user interface your product may not have the appeal needed to keep your customers happy. This issue can…
This article shows how to deploy dynamic backgrounds to computers depending on the aspect ratio of display
This video Micro Tutorial shows how to password-protect PDF files with free software. Many software products can do this, such as Adobe Acrobat (but not Adobe Reader), Nuance PaperPort, and Nuance Power PDF, but they are not free products. This vide…
In this video, viewers will be given step by step instructions on adjusting mouse, pointer and cursor visibility in Microsoft Windows 10. The video seeks to educate those who are struggling with the new Windows 10 Graphical User Interface. Change Cu…

688 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