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.
total answers (1)
start bookmarking useful questions and collections and save it into your own study-lists, login now to start creating your own collections.
Program:
The source code to demonstrate the named arguments is given below. The given program is compiled and executed successfully on Microsoft Visual Studio.
Output:
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.
In the above code, we passed arguments in the method using the named argument without any specific order.