Knowledge Walls
Gopal Rao
Mumbai, Maharashtra, India
Passcode:
C# program with class,object and constructors
1887 Views
Function 
This program is the example for class and object with constructor.In this program you will clear about constructor calling while object created for the class.
 
Code
	using System;
	using System.Collections.Generic;
	using System.Linq;
	using System.Text;
	
	namespace Class_Object
	{
	   class Program
	   {
	       static void Main(string[] args)
	       {
	           Student s = new Student("rony",50);
	           s.showData();
	           Student s1 = new Student(ref s);
	           s1.showData();
	           s.showData();
	           Console.ReadKey();
	        }
	   }
	   class Student
	   {
	       string name;
	       int age ;
	       public Student() { }
	       public Student(string name, int age){
	           this.name = name;
	           this.age = age;
	        }
	       public Student(ref Student st)
	       {
	           this.name = st.name;
	           this.age = st.age;
	           st.name = "Raj";
	        }
	       public void  showData()
	       {
	           Console.WriteLine("Object Contains   Name= {0}, Age ={1}",name ,age);
	        }
	    }
	}
Output 
  Copyright © 2014 Knowledge walls, All rights reserved
KnowledgeWalls
keep your tutorials and learnings with KnowledgeWalls. Don't lose your learnings hereafter. Save and revise it whenever required.
Click here for more details