=> Operator (C # retake)

Source: Internet
Author: User

=> The struct primitive is also a Lambda operator. It is used in lambda expressions to split the lambda main body on the right and the number of changes on the left. Lambda's formula is an inline formula of an anonymous method. It will be used in a large amount in the LINQ lookup representation in the method scheme method.

string[] words = { "cherry", "apple", "blueberry" };int shortestWordLength = words.Min(w => w.Length);Console.WriteLine(shortestWordLength);
 

=> The operation operator is "goes ". In the previous example, the formula is as follows: "minimum W steps] To W points length 」.

=> The operation operator and the assignment operator (=) have the same sort first in descending order and are right-aligned.

You can explicitly specify the type of the incoming variable, or let the compiler promote the type of the variable. In these cases, the data changes to strongrong typed during the peak period ). When you set the parameter, you must enclose the parameter name and variable name in Arc mode, as shown in the following example:

int shortestWordLength = words.Min((string w) => w.Length);

Multiple changes can be included in the arc, as shown in the following example.

Example

The following example illustrates how to create a Lambda formula with two variable numbers for the parameter query operator enumerable. Where. This formula returns all strings with a length smaller than the index position in the lower column.

Vbc # C ++ F # JScript
string[] digits = { "zero", "one", "two", "three", "four", "five",                     "six", "seven", "eight", "nine" };var shortDigits = digits.Where((digit, index) => digit.Length < index);foreach (var sD in shortDigits){    Console.WriteLine(sD);}// Output:// five// six// seven// eight// nine


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.