Understanding Predicate delegate with simple example in C#

Predicate is a delegate that always returns boolean value (True or False).

Predicate is used in conjunction with lambda expression.

Below example shows how can we simply replace static method with Predicate.


public class Program
{
 public static void Main()
 {
  
  Predicate<int> isGreaterThan5Predicate = m => m > 5;
  Console.WriteLine("Using Predicate to determine condition - 4 is not greater than 5 hence: " + isGreaterThan5Predicate(4));
  
  Console.WriteLine("Using static method to determine condition - 6 is greater than 5 hence: " + isGreaterThan5(6));

 }
 
 public static bool isGreaterThan5(int number)
 {
  return number > 5? true: false;
 }
}

Running above code will produce those messages in the console.

Using Predicate to determine condition - 4 is not greater than 5 hence: False
Using Predicate to determine condition - 6 is greater than 5 hence: True


Comments

  1. This is a very amazing post for cheap web hosting services. in this post, you have provided all the basic information regarding.

    website builder for reseller

    ReplyDelete
  2. Comfortabl y, the post is really the freshest on that deserving topic. I harmonise with your conclusions and definitely will thirstily look forward to your next updates.

    private label website builder

    ReplyDelete
  3. Thank you for the link building list.I am going jot down this because it will help me a lot.Great blog! Please keep on posting such blog.

    white label website builder

    ReplyDelete
  4. I am looking for and I love to post a comment that "The content of your post is awesome" Great work! Wordpress Tips

    ReplyDelete
  5. This is a nice and informative, containing all information and also has a great impact on the new technology. Thanks for sharing it
    website designing Service

    ReplyDelete
  6. Flutter Programming is one of the most popular in the cross platforms industry. We build excellent flutter mobile app and also learn how to overcome performance issues. is the best choice for all startups to discuss and get their project quotation. Offshore Flutter Development Service We also enable many startups to do Proof of concept and help them to learn about business decisions.

    ReplyDelete
  7. Crossplatform app development is challenging nowadays. many tools like a flutter and react-native are doing work really awesome. App development in Austin in cross-platform also have challenges like performance and network issue.

    ReplyDelete
  8. I am looking for and I love to post a comment that "The content of your post is awesome" Great work! สมัครเน็ตทรู

    ReplyDelete
  9. The article was up to the point and described the information very effectively. Thanks to blog author for wonderful and informative post.
    website designing

    ReplyDelete
  10. Financial sector has undergone drastic technological shifts in a comparatively short span of time. The shifts have been incorporated because of Growing Technology, Customer Demands, etc. Take a glance over some of the legacy Cross-platform App Development Company. These are so dynamic and efficient that it will cost you less time, more functionality, good output returns.

    ReplyDelete
  11. The world-famous search engine, Google has invested a substantial amount of time and resources on Flutter app development, especially for startups. At present we are residing in a highly dynamic world of web and mobile technologies, which is constantly growing at a very swift speed. However, the origin of cross-platform app development has revolutionized the market of mobiles for everyone including the developers, users, and all the other stakeholders.

    ReplyDelete
  12. It offers both powerful scripting and fast application development process across a vast range of fields. unindent does not match any outer indentation level python

    ReplyDelete
  13. IEEE Final Year Project centers make amazing deep learning final year projects ideas for final year students Final Year Projects for CSE to training and develop their deep learning experience and talents.

    IEEE Final Year projects Project Centers in India are consistently sought after. Final Year Students Projects take a shot at them to improve their aptitudes, while specialists like the enjoyment in interfering with innovation.

    corporate training in chennai corporate training in chennai

    corporate training companies in india corporate training companies in india

    corporate training companies in chennai corporate training companies in chennai

    I have read your blog its very attractive and impressive. I like it your blog. Digital Marketing Company in Chennai

    ReplyDelete

Post a comment