
Overloading of Constructors
ณัฐฌา อย่าเคลิ้มจิตร์ 650710542
Constructor Overloading
Ambiguous overloads
using System;
class Example
{
public Example(int a)
{
Console.WriteLine("Constructor with int");
}
public Example(double a)
{
Console.WriteLine("Constructor with double");
}
}
class Program
{
static void Main()
{
Example ex = new Example(5.0f); // Ambiguous overload
}
}ประโยชน์ของ Overloading Constructor
ตัวอย่างการ Overloading Constructor
1.By changing the number of the parameters
2.By changing the Data types of the parameters
3.By changing the Order of the parameters
4.Invoke an Overloaded Constructor using “this” keyword
Constructor Overloading ใน C# ต่างจากภาษาอื่นอย่างไร?
C#
Java
Python
C
Slide
Reference
Last updated

