2

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.

3
  • 1
    so I have 1 line of code that I couldn't understand what it means. You haven't told us which line it is that you don't understand... Commented Dec 6, 2018 at 10:55
  • 1
    @ardila it is obvious hehehe Commented Dec 6, 2018 at 10:55
  • Try searching Google for delegates. Commented Dec 6, 2018 at 10:56

2 Answers 2

7

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."

Sign up to request clarification or add additional context in comments.

1 Comment

Thank you for your answer :)
3

Can be simplified: if (!errors.Any(str.Contains)) return;.

It checks if any of the error-digits are contained in the string str as substring.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.