Techknow Study

C# Program-2.

10:26:00 PM vikas 0 Comments Category :


C#

Program-2

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

namespace constructor
{
    class Program
    {
        static void Main(string[] args)
        {
            string a = "", b = "";
            Console.WriteLine("enter name");
            student s = new student(a, b);
            a = s.Name = Console.ReadLine();
            b = s.Add = Console.ReadLine();
            Console.WriteLine("nmae={0} address={1}", a, b);
            Console.ReadLine();

        }
    }
    class student
    {
        private string name;//private variable start from small letter.
        private string add;

        public string Name//public variable start from capital letter.and we define a private member publicaly to set his properties.
        {
            get { return name; }
            set { }
        }
        public string Add
        {
            get { return add; }
            set { }
        }
        public student()
        { }
        public student(string name):this()//here this tag is used for chaining of constructor.
        {
            this.name = name;//here this tag is used to fix that the transfer o value. because here parameter and varibal of same name
                               //i.e. name and add.
        }
        public student(string name, string add):this(name)
        {
            this.name = name;
            this.add = add;
        }
      
    }
}

RELATED POSTS

0 comments