Advertisement
Guest User

Untitled

a guest
Feb 19th, 2019
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.21 KB | None | 0 0
  1. string[] books = new string[] { "Java", "SQL", "OOPS Concepts", "DotNet Basics"};
  2.  
  3. Predicate<string> longBooks = delegate(string book) { return book.Length > 5; };
  4. int numberOfBooksWithLongNames = books.Count(longBooks);
  5.  
  6. string[] books = new string[] { "Java", "SQL", "OOPS Concepts", "DotNet Basics"};
  7.  
  8. Func<string, bool> longBooks = delegate(string book) { return book.Length > 5; };
  9. int numberOfBooksWithLongNames = books.Count(longBooks);
  10.  
  11. var result = books.Count(x => x.Length > 5);
  12.  
  13. public bool IsThisALongBookTitle(string book)
  14. {
  15. return book.Length > 5;
  16. }
  17.  
  18. var result = books.Count(IsThisALongBookTitle);
  19.  
  20. string[]' does not contain a definition for 'Count' and the best extension method
  21. overload 'System.Linq.Enumerable.Count<TSource>
  22. (System.Collections.Generic.IEnumerable<TSource>, System.Func<TSource,bool>)'
  23. has some invalid arguments
  24.  
  25. Argument 2: cannot convert from 'System.Predicate<string>' to
  26. 'System.Func<string,bool>'
  27.  
  28. int numberOfBooksWithLongNames = books.AsEnumberable().Count(s => longBooks(s));
  29. int numberOfBooksWithLongNames = new List<string>(books).Count(s => longBooks(s));
  30. int numberOfBooksWithLongNames = books.Count(s => longBooks(s));
  31.  
  32. books.Count(a = > a.Length > 5);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement