Check List for duplications with optional words to exclude

后端 未结 4 1375
無奈伤痛
無奈伤痛 2021-01-20 03:31

I have a method as below. Method return either false/true either when list contains duplicates or not. I would like to extend my method to say for instance (optional) that i

4条回答
  •  我在风中等你
    2021-01-20 04:08

    This will also help, using a 'params' in arguments and then doing Except()

      public static bool IsListContainsDuplicates(List list, params T[] optional)
            {
                return list.Except(optional).GroupBy(n => n).Any(c => c.Count() > 1);
            }
    

    You can call like this if you doesn't want to exclude anything:

    IsListContainsDuplicates(list)
    

    Else, just pass the params values, for example, if the list is an integer list then,

    IsListContainsDuplicates(list,5,4)
    

提交回复
热议问题