C # Advanced Features (iii) Action, func,tuple

Source: Internet
Author: User
Tags new set

The action and Func generic delegates are actually a. NET framework predefined delegate, which is an attribute introduced by 3.5. Basically covers all commonly used delegates, so it is generally not necessary to re-declare them.

The action series generic delegate, which is a delegate with no parameters returned, can have up to 16 arguments or no arguments; the Func series delegate is a delegate with a return value and can have up to 16 parameters;

Tuples are a new feature introduced in C # 4.0, which needs to be written based on the. NET Framework 4.0 or later. Tuples use generics to simplify the definition of a class.

Provides a static method for creating a tuple object. You can provide up to 8 tuples, or eight tuples, to create a new set.

Action

 Public Delegate void Action ()

//void Method ();Action test1 = () = {Console.WriteLine ("void Method ();"); };//void Method (x);action<int> test2 = (x) = = {Console.WriteLine ("void Method (T1)"); };//void Method (x, y);action<int,int> test3 = (x, y) = = {Console.WriteLine ("void method (T1, T2)"); };
 Public Delegate void action<in (in) in   in in in  T16> ()

Func

 Public Delegate TResult func< out tresult> ()
// int method (); func<intten; // int method (x); func<intint2; // int method (X,X); func<intint int > TEST6 = (x, y) + x * y;
 Public Delegate TResult func<in in   in in in  out Tresult> ()

Tuple

 Public Static Tuple<t1> create<t1>(    T1 item1)var tuple1 = tuple.create (1); Console.WriteLine (Tuple1. ITEM1);      // Displays 1 var New tuple<int> (1); Console.WriteLine (Tuple1. ITEM1);      // Displays 1

Tuple.create<t1, T2, T3, T4, T5, T6, T7, t8>methods (T1, T2, T3, T4, T5, T6 , T7, T8)varPrimes =Newtuple<int,int,int,int,int,int,int, Tuple<int>> (1,2,3,4,5,6,7,Newtuple<int> (8));//The progenitor can be nested inside the yuan
tuple<int,int,int,int,int,int,int, tuple<int,int,int>> test =

Newtuple<int,int,int,int,int,int,int, tuple<int,int,int>> (1,2,3,4,5,6,7,Newtuple<int,int,int> (8,9));

Ganso accurate can be said to have multiple return values of a method, without the use of ref,out, more convenient.

C # Advanced Features (iii) Action, func,tuple

Related Article

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.