Home > Backend Development > C#.Net Tutorial > What are the different ways of overloading methods in C#?

What are the different ways of overloading methods in C#?

王林
Release: 2023-09-10 15:13:05
forward
661 people have browsed it

C# 中重载方法有哪些不同的方式?

Different ways of overloading methods are-

The datatypes of parameters are different
The number of parameters are different
Copy after login

An example is given below for different data types of parameters-

void print(int i) {
   Console.WriteLine("Printing int: {0}", i );
}

void print(double f) {
   Console.WriteLine("Printing float: {0}" , f);
}

void print(string s) {
   Console.WriteLine("Printing string: {0}", s);
}
Copy after login

The following columns Out of different number of parameters -

// two parameters
public static int mulDisplay(int one, int two) {
   return one * two;
}

// three parameters
public static int mulDisplay(int one, int two, int three) {
   return one * two * three;
}

// four parameters
public static int mulDisplay(int one, int two, int three, int four) {
   return one * two * three * four;
}
Copy after login

The above is the detailed content of What are the different ways of overloading methods in C#?. For more information, please follow other related articles on the PHP Chinese website!

source:tutorialspoint.com
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template