Wednesday, 21 September 2016
Simple Explanation of User Defined Default Constructor and Example Program C#
Here I will explain about User Define Default Constructor with an example program.
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);
}
}
}
- 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);
}
}
}
Subscribe to:
Post Comments
(
Atom
)
No comments :
Post a Comment