문제

I want to remove same value from two var variable, This is what i have tried.

var  first_list =   [1,10,12,20] ;
var  sec_list   =   [1,10,12,20,56];

sec_list.RemoveAll(first_list.Contains);

But it' snot working, values are not removed.

This is the expected result

sec_list = [56]

도움이 되었습니까?

해결책

I believe you want sec_list = { 56 }.

int[] first_list = { 1, 10, 12, 20 };
int[] sec_list = { 1, 10, 12, 20, 56 };
sec_list = sec_list.Except(first_list).ToArray();

다른 팁

Try below code

int[] first_list = { 1, 10, 12, 20 };
int[] sec_list = { 1, 10, 12, 20, 56 };
var list = sec_list.Except(first_list);
sec_list = list.ToArray();
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top