Home > Net >  Whether this constructor overload
Whether this constructor overload

Time:10-03

Designed a MyArray on class, in the hope that in the input array of different parameters (one dimensional array and two-dimensional arrays and jagged arrays), realize the constructor of overloading, the code is as follows:

Using System;
Using System. Collections. Generic;
Using System. Linq;
Using System. The Text;
Using System. The Threading. The Tasks;

The namespace ConsoleApp1
{
The class MyArray on
{
Public int no;
Public string [] Numbers;
Public string [and] names;
Public string [] [] scores;

Public MyArray on ()
{
This. No=0;
}
Public MyArray on (string [] Numbers)
{
This. No=1;
This. Numbers=Numbers;
}
Public MyArray on (string [and] names)
{
This. No=2;
This. Names=names;
}
Public MyArray on (string [] [] scores)
{
This. No=3;
This. Scores=scores;
}

Class Program
{
The static void Main (string [] args)
{
String [] mf3={" c ", "c + +", "c #"};
MyArray on myArray1=new MyArray on ();
MyArray1. No=1;
MyArray1. Numbers=mf3;
Console. WriteLine (" calls the default constructor output a one-dimensional array Numbers ");
{foreach (string I mf3 in) System. The Console. WriteLine (I); }

Siblings, string []=new string [and] {{" Mike ", "Amy"}, {" Mary ", "Albert"}};
MyArray on myArray2=new MyArray on (string [and] siblings);//compile it cannot through
Console. WriteLine (" call arguments constructor output multidimensional array names ");
The foreach (string I in siblings) {Console. Write (" {0} ", I); }
}
}
}
}


The above code at compile time cannot pass, could you tell me why?
  •  Tags:  
  • C#
  • Related