Gives solution for any Error occurs in any Programming Language, .Net Core 3.1, 3.0, C#,Asp.Net,Sqlserver,MVC,Java,Php,Html,Css,Jquery,errors and solutions,Latest News,Technology

Wednesday 21 September 2016

Simple Explanation of User Defined Default Constructor and Example Program C#

No comments :
Here I will explain about User Define Default Constructor with an example program.

  • User Defined Default Constructor  is created by the programmer.
  • User Defined Default Constructor doesn't accept any arguments/parameters
  • In general this constructor is used to initialize required values into the database.
  • But there is no restriction to write particular code into the constructor.

Example:

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

namespace ConsoleApplicationEF
{
    class Program
    {
        public int sno, age;
        public string sname, saddr;
        public Program() {
            this.sno = 1001;
            this.sname = "Ramesh";
            this.age = 25;
            this.saddr = "Hyderabad";
        }
        static void Main(string[] args)
        {
            Program p = new Program();
            Console.WriteLine(p.sno);
            Console.WriteLine(p.sname);

        }
    }
}

No comments :

Post a Comment