Lambda expressions, Action, Func and predicate

Source: Internet
Author: User

Http://www.tutorialsteacher.com/csharp/csharp-action-delegate

Lambda expression

Action,func

What are lambda expressions and what are the advantages of not using lambda

Its purpose: To simplify the code.

In Java, it is common to use interfaces to implement

Action is also a delegate type defined in the System namespace. An action type delegate are the same as Func delegate except that the action delegate doesn ' t return a value. In the other words, an Action delegate can is used with a method, which has a void return type.

Action is also a delegate type it can also deduce two conclusions.

1. Action is a type, similar to an int, so you can define a variable that defines what type of variable the meaning of the variable is. One of the following inferences is required.

2. Action is a delegate type, which is a delegate, which is a function pointer that is used for calls between methods.

It contains all the characteristics of delegate, and it is different.

3. With delegate there is an action and the action is used to simplify it.

public delegate void Print(int val);

Delegate it needs to be defined first and defines the method name

Action<int>  其就直接定义形参的类型且不要返回值。
Advantages of Action and Func delegates:
    1. Easy and quick to define delegates.
    2. Makes code short.
    3. Compatible type throughout the application.

"Action its use of the scene"

1. Use between threads in a frame

This._readthread = Threadex.threadcall (new Action (this). Readthread));

public static System.Threading.Thread Threadcall (System.Action Action)
{
Return Threadex.threadcall (action, NULL);
}

public static System.Threading.Thread Threadcall (System.Action Action, string name)
{
Return Threadex.call (action, name);
}

public static System.Threading.Thread Call (System.Action Action, string name)
{
System.Threading.Thread Thread = new System.Threading.Thread (new System.Threading.ThreadStart (action). Invoke));
if (name! = NULL)
{
Thread. name = name;
}
Thread. Start ();
return thread;
}

Lambda expressions, Action, Func and predicate

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.