How to reference another constructor in c#? For example
class A
{
A(int x, int y) {}
A(int[] point)
{
how to call A(point.x, point.y}?
)
}
How to reference another constructor in c#? For example
class A
{
A(int x, int y) {}
A(int[] point)
{
how to call A(point.x, point.y}?
)
}
You can use keyword this
in the "derived" constructor to call the "this" constructor:
class A
{
A(int x, int y) {}
A(int[] point) : this(point[0], point[1]) { //using this to refer to its own class constructor
{
}
}
That aside, I think you should get the value in array by indexes: point[0], point[1]
instead of doing it like getting field/property: point.x, point.y
It's pretty simple. Same way you would call a base constructor.
A(int[] point) : this(point[0], point[1])
{
}