What are the different ways of overloading in C# (C Sharp)?

There are three different ways of overloading in C#. They are listed below:




• Method Overloading: Same method name can be overloaded with different set of arguments in its signature.
• Constructor Overloading: Constructor of a class can be overloaded with a different set of arguments in its signature.
• Operator Overloading: Every operator of C# has predefined meaning. C# provides you an option to give a new meaning for an operator using operator overloading.

Here is an example demonstrating method overloading in C#:

class sampleClass {
int member1;
string member2;
public void setData(int data) {
member1 = data;
}
public void setData(string data) {
member2 = data;
}
public static void Main() {
sampleClass obj = new sampleClass();
obj.setData(10);
obj.setData(“Hello”);
}
}

_______________________________________________________________________

Add to My Yahoo!


FREE Subscription

Subscribe to our mailing list and receive new articles
through email. Keep yourself updated with latest
developments in the industry.

Name:
Email:

Note : We never rent, trade, or sell my email lists to
anyone. We assure that your privacy is respected
and protected.

Visit .NET Programming Tutorial Homepage

______________________________________________________

Recommended Resource

| Can you call a constructor from another constructor of the Class in .NET? | Difference between Response.Output.Write() method and Response.Write() method in .NET | How do you establish multiple inheritance in C#? | How do you introduce a ReadOnly property in C#? | How do you perform constructor overloading in C#? | Is catch(Exception) recommended to be used in .NET? | What are the different access modifiers available in C#? | What are the different ways of overloading in C#? | What are the members of stringbuilder class in C#? | What is Multicast Delegate? Explain it with example in C# | What is the difference between abstract class and interface in .NET? | What is the difference between Clone and CopyTo methods in .NET | What is the difference between const and readonly in .NET | What is the difference between directcast and ctype in .NET? | What is the difference between out and ref parameters in .NET | What is the difference between public assembly and private assembly in .NET | What is the difference between strong typing and weak typing in .NET? | What is the difference between Trace and Debug in .NET | What is the need for Abstract Factory Pattern in C#? | What is the need for Adapter Pattern in C# |


| Privacy Policy for www.dotnet-guide.com | Disclosure | Contact |

Copyright - © 2004 - 2017 - All Rights Reserved.