Jan 23, 2020

PREDICATE DELEGATE IN C# (GENERIC DELEGATE p-3)

c# predicate delegate, c# delegate, delegate,predicate delegate, example of predicate delegate, predicate delegate example,lambda expression in c#
predicate delegate in c# 

PREDICATE DELEGATE IN C#

            Predicate delegate is one of the generic delegate which is used when our method return the value type as bool means the method just only return true or false, it is used for the bool values returning methods. ‘Predicate’ is the keyword for the use of this delegate it is compulsory that the method must have the return value as bool.
            In this part there is no overload method only delegate that’s accepts one parameter that has to pass and about return type predefined it already know the return values or output type either it may be true or false. So no need to explain output type only parameter list along with predicate keyword. but in Func delegate it is require to tell the output type. and the action delegate which have no return type

Syntax of predicate delegate

Predicate <parameter list > Obj = <method name> 
In place of predicate we can use func delegate how can? By explained that the parameter passing data type and return always will be bool. Syntax will be
func <parameter list, bool > Obj = <method name>
but it is better to use the predicate instead of func. 
It can be short if we use lambda expression on Predicate delegate not only Predicate all the three generic delegate can make easy by using lambda expression how can we make it just remove the method name and specify the lambda expression  as we did in lambda expression part like this.
Action <formal parameter type only > Obj = (actual parameter list only name) =>
{
            Method implementation;
}
you can see what is formal parameter and actual parameter by clicking on them.
            Predicate delegate contain only one delegate no more overload that take one parameter and return one output that are either true or false only which is as in table
Sr.no
Delegate
Parameter list
Return value number
1
One delegate
1 parameter
One return type
True/false

ACTION DELEGATE IN C#(GENERIC DELEGATE p-2)

action delegate, c# action,c# lambda, lambda syntax, action delegate example, example of action delegate in c#, c# delegate
action delegate in c#


ACTION DELEGATE IN C#

           "Action delegate is one of the generic delegate it is used, if all that you have a method that return nothing for this method we use action delegate the method should be void in return type. ‘Action’ is the keyword. Simply it is used for non-value returning methods. In Func delegate we have parameter passing along with return values but in action delegate we can any parameter but we can’t have any return value. Here we have 16 overloaded delegates all have different parameter number but zero returning values which explain in table
Sr.no
Delegate
Parameter list
Return value number
1
1st delegate
1 parameter
Zero return type
2
2nd delegate
2 parameters
Zero return type
3
3rd delegate
3 parameters
Zero return type
4
4th delegate
4 parameters
Zero return type
5
5th delegate
5 parameters
Zero return type
6
6th delegate
6 parameters
Zero return type
7
7th delegate
7 parameters
Zero return type
8
8th delegate
8 parameters
Zero return type
9
9th delegate
9 parameters
Zero return type
10
10th delegate
10 parameters
Zero return type
11
11th delegate
11 parameters
Zero return type
12
12th delegate
12 parameters
Zero return type
13
13th delegate
13 parameters
Zero return type
14
14th delegate
14 parameters
Zero return type
15
15th delegate
15 parameters
Zero return type
16
16th delegate
16 parameters
Zero return type

Syntax
Action <parameter list > Obj = <method name>
Here we no need to explain the return type because it will be non-value return method. Action is the keyword parameter list will contain the passing parameter that can be any nature data type Obj will object name by which we call the delegate by passing the parameter and finally the method name replaced by that method name which will use to bind with this delegate.
It can be short if we use lambda expression on Action delegate not only Action all the three generic delegate can make easy by using lambda expression how can we make it just remove the method name and specify the lambda expression  as we did in lambda expression part like this.
Action <formal parameter type only > Obj = (actual parameter list only name) =>
{
            Method implementation;
}
you can see what is formal parameter and actual parameter by clicking on them.

C# FUNC DELEGATE(GENERIC DELEGATE p-1)


func, delagate, c# , c# delegate, func lamdba expression example, func delegation in c#
c# func delegate

GENERIC DELEGATE

            “The entire predefined delegates are known as generic delegate. Actually in our base class library we found some predefined delegate by the programmer and we just use them in our program/project to fulfill our requirements is called generic delegate.”
The advantage of generic delegate is that we need not to defined an explicit delegate for the methods separately, in place of this we use the generic delegate at the time of creating instance we just use the keyword and make it possible example will clear the confusions.
            There are three basic predefined or generic delegate in our system.io is

FUNC DELEGATE IN C#

            Func delegate use when we have a method that returns value, simple it is used for the value returning methods. Actually ‘Func’ is the keyword to call the delegates. The Func delegate contain 17 overload delegate in it for which in sequence all delegates accept different types of  parameter but return one result/value that’s are below in the table
Sr.no
Delegate
Parameter list
Return value number
1
1st delegate
Zero parameter
One return type
2
2nd delegate
1 parameter
One return type
3
3rd delegate
2 parameters
One return type
4
4th delegate
3 parameters
One return type
5
5th delegate
4 parameters
One return type
6
6th delegate
5 parameters
One return type
7
7th delegate
6 parameters
One return type
8
8th delegate
7 parameters
One return type
9
9th delegate
8 parameters
One return type
10
10th delegate
9 parameters
One return type
11
11th delegate
10 parameters
One return type
12
12th delegate
11 parameters
One return type
13
13th delegate
12 parameters
One return type
14
14th delegate
13 parameters
One return type
15
15th delegate
14 parameters
One return type
16
16th delegate
15 parameters
One return type
17
17th delegate
16 parameters
One return type

Syntax
Func <parameter list, return type > Obj = <method name>
Func is the keyword and then parameter list that how many parameter that have to pass according to programmer return type we have to explain which type of value should be return either may be int, double , string or bool etc. Obj is the object name it may be on the programmer chose he can named any name such as a , b h ,cd, nor etc. etc.  and last the method name in the place of this that method name come that should bind to this delegate the syntax is same for all three generic delegate while changing the first keyword from func to action and predicate but all other steps will be same. Calling will same as delegate calling. See it.
Func <parameter list only type, return type > Obj = <method name>
It can be short if we use lambda expression on Func delegate not only Func all the three generic delegate can make essay by using lambda expression how can we make it just remove the method name and specify the lambda expression  as we did in lambda expression part like this.
Func <formal parameter list only type, return type > Obj = (actual parameter list only name) =>
{
            Method implementation;
}
you can see what is formal parameter and actual parameter by clicking on them.

LAMBDA EXPRESSION IN C#

lambda expression in c# ,c# delegate, lambda expression java,lambda expression python,lambda expression c#,lambda expression, example of lambda expression
c# lambda expression 

LAMBDA EXPRESSION IN C#

“Lambda expression is just a short hand for write the anonymous method, means it is a simple method to write an anonymous method”.  Lambda expression is represented by => (Equal in sense of math and assignment operator in programming and then greater then operator) see the example for better understanding.
It will better understand if you have clear idea about anonymous method. In anonymous we taught about the removing of method defining and then binding with the delegate separately, simple and straight we defined and bound the unnamed method by the time of creating delegate instance. Like this
<Delegate-name> Obj = delegate (parameter list)
{
            Method implementation;
} ;
syntax of lambda expression is slightly change that is bellow.

Syntax of lambda expression

1.    It’s also included in three steps 1st step define delegate under name space of same signature that would be the method signature.
2.    In 2nd step using lambda expression define method and bind with thedelegate.
3.    And 3rd step call the method using the name of delegate.
All the steps that included in anonymous method defining, calling and instance creating. Lambda expression syntax is also same like that but here by bringing a little bit change in anonymous method syntax of creating instance we will make the lambda expression syntax but the remaining two steps that include the defining of delegate under namespace and calling will still same. Have a look to the above anonymous method syntax and then see this
<Delegate-name> Obj = (parameter name) =>
{
            Method implementation;
} ;
We remove the delegate keyword and data type form the anonymous method and use => in place of that that makes the codding easier and time saving but it will work like anonymous method that’s why lambda is called as the short hand writing for anonymous method.

Jan 22, 2020

ANONYMOUS METHOD IN C#


anonymous method, c# anonymous delegate,c# anonymous event handler,inline delegate c#
anonymous method in c#

ANONYMOUS METHODS IN C# 

            “A method without any name. Its consists of only body of method called anonymous method.” For which we use delegate keyword to define a method, and comes in the delegate topic.
It is suggested when the volume of code is less with in few lines thus it better to create an unnamed  method and bind with delegate instead of making an original method. We never anonymous when the method having g large volume of code.
SYNTAX

     1.    Defining delegate

First we have to define a delegate of some name under namespace and should clear the return type at time of delegate defining let suppose we have a delegate name as Greeting_Delegate ( ) then under namespaces like this here I clear the return type also.
            Public delegate string Greeting_Delegate (string str);

     2.    Instantiating the delegate and anonymous binding the method

Now instead of defining and instantiating an instance and calling we direct define the method at the time of creating the delegate in main class of program let see at time of instantiating the instance
            Greeting_delegate Obj = delegate (string str)
           {
                ;       // the statement that has to execute under this delegate calling.
};
We write delegate keyword after that the parameter list and no need to specify the return type because already at the time of delegate defining we specified the return type. See the examples.

     3.    Calling the delegate

Same like other delegate it has to call like them first Obj (object name) and then pass the parameter but it can be done in two way. Consider the example below
1st way == Obj (“Asif”);                           //consider the upper delegate
2nd way == Obj. invoke (“Asif”);            // by using invoke method

Jan 21, 2020

MULTICAST DELEGATE IN C#

delegate, multicast delegate,c# delegate, c# Multicast delegate example,example of multicast delegate, definition of multicast delegate
multicast delegate

MULTICAST DELEGATE

            “A delegate holds more than one method reference and can be call by that delegate name”.
            If we have more than one method with same signature, here signature take as the same return type and same parameter accepts. Than for those methods we use multicast delegate to call all that method with one delegate name.
            In this topic we will discuss about three step to perform multicast delegate.
    1.    Defining the delegate
It is same like as delegate that’s the delegate signature should match with method
     signature except name. The multi task will perform in creating instance part.
      SYNTAX
                        [< Modifier >] delegate <return type> Name (parameter list)
    2.    Instantiating the instance of multicast delegate
The main difference between delegate and multicast delegate is going to declare here. We will create multiple method reference by using one delegate name like this.
            <Delegate name> d.name = new <delegate name> (reference method)
This syntax can be return like this
            <Delegate name> d.name = <1st reference method>
            d.name += <2nd reference method >
Here we use d.name for both methods and when we give one time values theses method will execute by same value see the example to clarify.
    3.    Calling the multicast delegate
It is also same like delegate calling. Calling will do in two different ways.
1st way:   <d.name> (value1, value2… value n)         //as above mention d.name
2nd way:  <d.name>.invoke (value1, value2… value n)
When we call one time all the linked method will execute using same values.
Points to be noted while going to perform multicast delegate
            There some points that should keep in mind when decide to make multicast delegate that’s
1.    We use multicast delegate in such a time where multi method has to execute by same values.
2.    Before using of this delegate make sure that all your methods are non-value returning type otherwise only the last method result will be shown and rest all are overwrites by the last one. If your methods are value returning type it better to use delegate instead of multicast delegate.

Jan 19, 2020

DELEGATE IN C#


c# delegate example,delegate,delegate meaning,multicast delegate in c#,use of delegates in c#
c# delegate

DELEGATE

            “Delegate is a point safe function pointer which is responsible to call a method and hold the reference to execute the method”.
            It is a user type and reference type which should be declares under a namespace. To perform delegate we have to do three steps

          1.    Defining a delegate

The syntax of delegate same like as method signature but we have to add delegate word extra see this,
            [<Modifier>] delegate <return type> <Name> [(parameter list)];
Here some point to be noted,
First point is the return type of the delegate must same to the method and the
Parameter list also must same to build delegate of a method.
            Second point is the name of the method and delegate must different for which we are going to make a delegate.
            If the method is static you need to declare the delegate also static because by default delegates are static. 
        2.    Instantiating instance of the delegate
Due to the delegate is reference type we have to instantiate the instance of delegate. This step is also similar to the method instantiating like this
<delegate name> db= <new> <delegate name> (method name)
db is nothing just name like we use the object name. example will clear it.
Here also two point to be noted
            First one while instantiating you have to pass the method name for which we build the delegate instead of giving parameter values.
            Second point is if the method is static it is directly call in method name if the main and delegate are in same class otherwise you need to give the class name as we did in the static method to execute, if it is non-static you should have to go with the reference or instance to call the method name in delegate method name.
        3.    Call the delegate
Where we call the delegate by passing the required values, but internally actually the method that is bound with the delegate get execute and give us the results. Like this
<Delegate name ‘db’> (parameter);   //db as we use for delegate instance.