Event is actually just a keyword that you place in front of a delegate to prevent an outside class from invoking said delegate or tampering with the delegate’s invocation list ( except to subscribe / unsubscribe itself ) In this…
Event is actually just a keyword that you place in front of a delegate to prevent an outside class from invoking said delegate or tampering with the delegate’s invocation list ( except to subscribe / unsubscribe itself ) In this…
2 issues in our previous example ( See Implementing the Observer Pattern via Delegates post ) 1. I can invoke the TrainSignal delegate directly This means the TrainSignal object will tell subscribers that a train is coming when it’s not…
What is the Observer Pattern ? Make use of the Observer Pattern in situations where 1. You have an object -> Object A 2. Object A has 1 or more dependent objects -> Object A, Object B and Object C…
Func explained Func is a generic delegate supplied for your use by the language. You can use Func instead of creating your own delegate. Func always returns a value. Func is overloaded and can take up to 16 input arguments…
Generics allow you to write a class or method that can work with any data type. You find yourself creating a bunch of similar classes where the only difference are the data-types e.g. The three classes below are the same,…
A static class is basically the same as an instance class. The main difference is that a static class cannot be instantiated – you cannot create an instance of the static class via the “new” keyword. Given that you cannot…
I had previously written that a delegate is a class containing a reference to a method. A delegate can actually contain a reference to multiple methods ( which can be in different classes ). When a delegate contains multiple targets, this is…
A lambda expression is a method without a declaration – so no access modifier, no return value declaration and no name. Why should I use a lambda expressions ? 1. Reduces typing – I don’t need to specify the name…
C# Delegates – Why Delegates ? Why would you go to the trouble of creating a delegate when you could just call the method directly ? This question is often asked when delegates are first introduced. Consider the function static…
What is a delegate ? A delegate is a class containing a reference to an method. Pretty vague…so here is an example Console application which returns the day of the week as a string Without using delegates Using Delegates How…