Named and optional arguments

Named Arguments :

This helps us to send the arguments in the order you wish.
Just add the variable name to which you are passing the value

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApplication6
{
    class Program
    {
        static void Main(string[] args)
       {
           int eno;
           string eName;
           double sal;
           Console.Write("enter Eno :");
           eno = Convert.ToInt32(Console.ReadLine());
           Console.Write("enter Ename :");
           eName = Console.ReadLine();
           Console.Write("enter Sal :");
           sal = Convert.ToDouble(Console.ReadLine());

           employee e = new employee();
           e.getData(name: eName, sal: sal, eno: eno);
           e.ReadData();
           Console.Read();
       }
    }
    class employee
    {
        private int eno;
        private string eName;
        private double sal;
        public void ReadData()
        {
            Console.WriteLine("Eno :" + eno);
            Console.WriteLine("Ename :" + eName);
            Console.WriteLine("Sal : " + sal);

        }
        public void getData( int eno, string name , double sal )
        {
            this.eno = eno;
            eName = name;
            this.sal = sal;
   
        }
    }
}

Named and optional arguments Named and optional arguments Reviewed by Share less to Learn More on 7:19 PM Rating: 5

No comments