search
Home类库下载C# class libraryC# optional parameters and named parameters

Optional parameters

static void test1()
{
    func1("A");
    func1("B", 30);
    Console.ReadKey();
}
static void func1(string name, int age = 20)
{
    Console.WriteLine("Name: " + name + "\t Age: " + age);
}

Named parameters

static void test2()
{
    func2("C", 40);
    func2(age: 50, name: "D");
    Console.ReadKey();
}
static void func2(string name, int age)
{
    Console.WriteLine("Name: " + name + "\t Age: " + age);
}

Optional parameters combined with named parameters

static void test3()
{
    func3("E");
    func3("F", 10, false);
    func3("G", 15);
    func3("H", isMale: false);
    Console.ReadKey();
}
static void func3(string name, int age = 20, bool isMale = true)
{
    Console.WriteLine("Name: " + name + "\t Age: " + age + "\t IsMale: " + isMale);
}


Statement
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Safe Exam Browser

Safe Exam Browser

Safe Exam Browser is a secure browser environment for taking online exams securely. This software turns any computer into a secure workstation. It controls access to any utility and prevents students from using unauthorized resources.

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SAP NetWeaver Server Adapter for Eclipse

SAP NetWeaver Server Adapter for Eclipse

Integrate Eclipse with SAP NetWeaver application server.

SublimeText3 Linux new version

SublimeText3 Linux new version

SublimeText3 Linux latest version