Ylbtech-languagesamples-namedandoptional (named and optional parameters)

Source: Internet
Author: User

Ylbtech-microsoft-csharpsamples:ylbtech-languagesamples-namedandoptional (named and optional parameters)

1.A, example (sample) back to top
Named and optional parameters

C # 4.0 supports named and optional parameters. This program demonstrates how to declare a method with a named and optional parameter, and how to invoke the method by using the default value of the parameter and by explicitly naming a specific parameter.

1.B, sample code back to top

1.b.1, Program.cs

usingSystem;usingSystem.Collections.Generic;usingSystem.Linq;usingSystem.Text;namespacenamedandoptional{//This program demonstrates how to use a method that declares a named parameter and an optional parameter.//and how to explicitly use it while calling the method//named parameters and optional parameters.     classProgram {//methods with named parameters and optional parameters         Public Static voidSearch (stringNameintAge = +,stringCity ="Pueblo") {Console.WriteLine ("Name = {0}-age = {1}-city = {2}", name, age, city); }        Static voidMain (string[] args) {            //Standard CallSearch ("Sue", A,"New York"); //Omit City parameterSearch ("Mark", at); //To explicitly name the city parameterSearch ("Lucy", City:"Cairo"); //use named parameters in reverse orderSearch ("Pedro", Age: $, City:"Saigon"); }    }}
View Code

1.b.2,

1.C, (free Download) back to top

Ylbtech
Source: http://ylbtech.cnblogs.com/
This article is copyright to the author and the blog Park, Welcome to reprint, but without the consent of the author must retain this paragraph, and in the article page obvious location to the original link, otherwise reserves the right to pursue legal responsibility.

Ylbtech-languagesamples-namedandoptional (named and optional parameters)

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.