Overloading: Overloading of methods in a class specify that the name of methods are same but there parameter will be different which is passed in that methods. In other word there are two or more methods are available in class with same name but all methods have different parameters(different- sequence, type, number of parameters). It is automatically find suitable methods which type value passes in constructor of its class when create instance.
exp-
class Demo
{
public void Test(string name)
{
Console.WriteLine('Your name is'+name);
}
public void Test(int age)
{
Console.WriteLine('your age is'+age);
}
public void Test(string name, int age)
{
Console.WriteLine('your name is '+name+' and your age is '+age);
}
}
class OverloadingExp
{
static void Main(string[] arg)
{
Demo demo = new Demo();
demo.Test('Ashutosh \n');
demo.Test(24+'\n');
demo.Test('Ashutosh',24);
}
}
Output- Your name is Ashutosh
Your name is 24
your name is Ashutosh and your age is 24
Overriding: In C#, overriding of methods is just like overloading of methods in program but in case of overring there all methods with same name is created in different class with same parameter. Or in method overriding method name is same and parameters are also same of all methods (same- sequence, types, number of parameters) but all methods are created in different class.
Exp-
public class Examp
{
public void Task(string name, int id)
{
Console.WriteLine('Name:{0}',name +' Id: '+ id);
}
}
public class Exp
{
public void Task(string name, int id)
{
Console.WriteLine('Name:{0}',name + 'Id: '+id);
}
}
public class Mark
{
public void Task(string name, int id)
{
Console.WriteLine('Name:{0}',name + 'Id: '+ id);
}
}
class OverridigExp
{
static void Main(string[] arg)
{
Examp exe = new Examp();
exe.Task('Examp',001);
Exp exp = new Exp();
exp.Task('Exp ' ,002);
Mark mark = new Mark();
mark.Task('Mark ', 003); } }
Output- Name: Examp Id: 1
Name: Exp Id: 2
Name: Mark Id: 3
Markdown for AI
A clean, structured version of this page for AI assistants and LLMs.
We use cookies to ensure you have the best browsing experience on our website. By using our site, you
acknowledge that you have read and understood our
Cookie Policy &
Privacy Policy.
Overloading: Overloading of methods in a class specify that the name of methods are same but there parameter will be different which is passed in that methods. In other word there are two or more methods are available in class with same name but all methods have different parameters(different- sequence, type, number of parameters). It is automatically find suitable methods which type value passes in constructor of its class when create instance.
exp-
Output- Your name is Ashutosh
Your name is 24
your name is Ashutosh and your age is 24
Overriding: In C#, overriding of methods is just like overloading of methods in program but in case of overring there all methods with same name is created in different class with same parameter. Or in method overriding method name is same and parameters are also same of all methods (same- sequence, types, number of parameters) but all methods are created in different class.
Exp-
Output- Name: Examp Id: 1
Name: Exp Id: 2
Name: Mark Id: 3