Вопрос

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