Q:

C# program to demonstrate the named arguments

0

C# program to demonstrate the named arguments

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

Program:

The source code to demonstrate the named arguments is given below. The given program is compiled and executed successfully on Microsoft Visual Studio.

//C# program to demonstrate the named arguments.

using System;

class Employee
{
    static public void PrintEmployee(int id, string name, int salary, string department)
    {
        Console.WriteLine("Employee Details:");
        Console.WriteLine("\tEmployee Id        : " + id          );
        Console.WriteLine("\tEmployee Name      : " + name        );
        Console.WriteLine("\tEmployee Salary    : " + salary      );
        Console.WriteLine("\tEmployee Department: " + department  );
    }

 
    static public void Main()
    {
        PrintEmployee(101, "RAHUL", 10000, "HR"     );
        PrintEmployee(102, "ROHIT", 12000, "Sales"  );
        PrintEmployee(id:103,salary:15000, name:"VIRAT", department:"Account");
    }
}

Output:

Employee Details:
        Employee Id        : 101
        Employee Name      : RAHUL
        Employee Salary    : 10000
        Employee Department: HR
Employee Details:
        Employee Id        : 102
        Employee Name      : ROHIT
        Employee Salary    : 12000
        Employee Department: Sales
Employee Details:
        Employee Id        : 103
        Employee Name      : VIRAT
        Employee Salary    : 15000
        Employee Department: Account
Press any key to continue . . .

Explanation:

In the above program, we created the Employee class that contains two static methods PrintEmployee() and Main().

The PrintEmployee() method is used to print the employee details on the console screen.

In the Main() method, we called the PrintEmployee() methods.

PrintEmployee(id:103,salary:15000, name:"VIRAT", department:"Account");

In the above code, we passed arguments in the method using the named argument without any specific order.

 

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

Similar questions


need a help?


find thousands of online teachers now