Câu hỏi phỏng vấn C#
Câu hỏi

What are the different ways...

Câu trả lời

Here are the different ways a method can be overloaded in C#:

Method Overloading by Number of Parameters

You can overload a method by having different numbers of parameters. For example:

csharp Copy
public int Add(int a, int b) { return a + b; }
public int Add(int a, int b, int c) { return a + b + c; }

Method Overloading by Type of Parameters

You can overload a method by having parameters of different data types. For example:

csharp Copy
public int Add(int a, int b) { return a + b; } 
public double Add(double a, double b) { return a + b; }

Method Overloading by Order of Parameters

You can overload a method by having the parameters in a different order. For example:

csharp Copy
public int Multiply(int a, int b) { return a * b; }
public int Multiply(int b,...
senior

senior

Gợi ý câu hỏi phỏng vấn

senior

What is the difference between Func<string,string> and delegate ?

junior

How is Exception Handling implemented in C#?

expert

in C#, when should we use abstract classes instead of interfaces with extension methods?

Bình luận

Chưa có bình luận nào

Chưa có bình luận nào