Keep it Simple

// practice, the distance between dream and achievement

Tag: Event

Event – want event to run only once using add/remove properties.

It is a common scenario where you may want to ensure that object is subscribed to an event only once, this can be done easily as shown below

Continue reading

Delegate vs Event in C#?

A delegate in C# is a type-safe function pointer with a built in iterator.

Example with Delegates (Action in this case that is a kind of delegate that doen’t return value)

 

Continue reading

Recursive function using Action in C#

As you know, action is a delegate (pointer) to a method, that takes zero, one or more input parameters, but does not return anything. In this post, we will see how to implement a recursive lambda expression to traverse a tree structure in C#.

Continue reading

Action vs Func vs Predicate in C#

The purpose of writing this article is simple; to provide a simple and fresh demonstration of Action vs Func vs Predicate keyword in C#.

Though widely used with Linq, Action and Func are concepts logically independent of Linq. C++ already contained the basic concept in form of typed function pointers.

  • Action is a delegate (pointer) to a method, that takes zero, one or more input parameters, but does not return anything.
  • Func is a delegate (pointer) to a method, that takes zero, one or more input parameters, and returns a value (or reference).
  • Predicate is a function pointer for method which returns boolean value. They are commonly used for iterating a collection or to verify if the value does already exist.

Continue reading

© 2017 Keep it Simple

Theme by Anders NorenUp ↑