LINQ .Any to run method

    Professor Asked on October 18, 2020 in Android langue,   Linq.
    Add Comment
    1 Answer(s)

      Should be as simple as just using the Func<TSource,bool> predicate of Any then throwing on true

      Determines whether any element of a sequence satisfies a condition.

      predicate

      Func<TSource,Boolean>

      A function to test each element for a condition.

      Example

      if(hexSignatureList.Any(x => IsValidMimeType(x)))     throw new ArgumentException("Invalid."); 

      Or using as a Method Group

      if(hexSignatureList.Any(IsValidMimeType))     throw new ArgumentException("Invalid."); 
      Professor Answered on October 18, 2020.
      Add Comment

      Your Answer

      By posting your answer, you agree to the privacy policy and terms of service.