Pages

Sunday, 14 October 2012

Write a C# program to print student details using constructor and destructor.

Write a C# program to print student details using constructor and destructor.

Description:
In this post we are going to learn constructor and destructor.

Open Microsoft visual studio
File-> New -> Project -> visual c#-> console Application

Program:


using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace _5.Constructor
{
    class Program
    {
        static void Main(string[] args)
        {
            student s = new student("sizar",21);                                                                    
            Console.ReadKey();
   }
    }
    public class student
    {
        String name;
        int id;
        public student(String name, int id)
        {
            this.name = name;
            this.id = id;
            Console.WriteLine("\n Constructor Called..!\n");
            Console.WriteLine("Student Name:{0}",name);
            Console.WriteLine("Student id:{0}", id);
        }
        ~student()
        {
            Console.WriteLine("\nDestructor Called..!");
            Console.ReadLine();
        }
    }


Demo:
Write a C# program to print student details using constructor and destructor.
Write a C# program to print student details using constructor and destructor.
                              

Write a C# program to print student details using constructor and destructor.
Write a C# program to print student details using constructor and destructor.
                     



Download Code:

No comments:

Post a Comment