Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

C# check specific string in string array

Tags:

c#

I have a line of code that I don't understand what it means, and I don't really know what I have to search on google to find some information about it:

private static string[] errors = new string[6] {"1","2","3","4","5","6"};

string str = httpRequest.Get(s + "'").ToString(); // s = url

if (!(errors).Any<string>(new Func<string, bool>(str.Contains)))
    return;

I know this might be a bad question or stupid question but I do want to understand what it does first before I continue with other stuff.

like image 587
Daniel Avatar asked Dec 05 '25 23:12

Daniel


1 Answers

It's not a bad question but code style:

  if (!(errors).Any<string>(new Func<string, bool>(str.Contains)))
       return;

can be rewritten into readable chunk as

  if (!errors.Any(item => str.Contains(item)))
      return;

which means "if errors collection doesn't have (!) Any item which Contains in str then return."

like image 148
Dmitry Bychenko Avatar answered Dec 08 '25 14:12

Dmitry Bychenko



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!