The this is a keyword, It refers to the current instance of the class.
It can be used to access members from within constructors,instance accessors instance methods and instance successor.
public class Demo4this
}
static void Main(string[] args)
It can be used to access members from within constructors,instance accessors instance methods and instance successor.
public class Demo4this
{
int age;
string name;
public Demo4this(int age, string name)
{
this.age = age;
this.name = name;
}
public void Show()
{
Console.WriteLine("Your Name : " + name);
Console.WriteLine("Your Age :" + age.ToString());
}}
static void Main(string[] args)
{
int age1;
string name1;
Console.WriteLine("Enter your name : ");
name1=Console.ReadLine();
Console.WriteLine("Enter your age : " );
age1=Int32.Parse(Console.ReadLine());
Demo4this obj = new Demo4this(age1, name1);
obj.Show();
Console.ReadLine();
Console.ReadLine();
}
}
}