Solved

C# Linq Remove All

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

Business Impact of IT Communications

What are the business impacts of how well businesses communicate during an IT incident? Targeting, speed, and transparency all matter. Find out more in this infographic.

Question has a verified solution.

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

Wouldn’t it be nice if you could test whether an element is contained in an array by using a Contains method just like the one available on List objects? Wouldn’t it be good if you could write code like this? (CODE) In .NET 3.5, this is possible…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…
I've attached the XLSM Excel spreadsheet I used in the video and also text files containing the macros used below. https://filedb.experts-exchange.com/incoming/2017/03_w12/1151775/Permutations.txt https://filedb.experts-exchange.com/incoming/201…

738 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