-1

私のエラーは for ステートメントにあり、構文エラーは、コンストラクターが 3 つの引数を取らないことを示しています。

        string[] first = new string[20] { "Scott", "Ramona", "Todd", "Melissa", "Naomi", "Leland", "Conor", "Julie", "Armondo", "Leah",
                                          "Frank", "Peter", "Ila", "Mandy", "Sammy", "Gareth", "Garth", "Wayne", "Freddy", "Mark" };

        string[] last = new string[20] { "Kennedy", "Kennedy", "Kennedy", "Kennedy", "Kennedy", "Kennedy", "Carrel", "MaloyTheBeautiful", "Johnson", "Smith", 
                                         "Sinatra", "Clemens", "Eels", "Johnson", "Eels", "Thompson", "Brooks", "World", "Crugar", "Thomas" };
        DateTime[] birth = new DateTime[20];
        birth[0] = new DateTime(1987, 22, 7);
        birth[1] = new DateTime(1962, 15, 9);
        birth[2] = new DateTime(1984, 21, 4);
        birth[3] = new DateTime(1977, 24, 1);
        birth[4] = new DateTime(1983, 12, 8);
        birth[5] = new DateTime(1979, 14, 1);
        birth[6] = new DateTime(1965, 19, 9);
        birth[7] = new DateTime(1968, 21, 2);
        birth[8] = new DateTime(1980, 22, 7);
        birth[9] = new DateTime(1982, 20, 7);
        birth[10] = new DateTime(1984, 19, 4);
        birth[11] = new DateTime(1968, 11, 9);
        birth[12] = new DateTime(1968, 21, 8);
        birth[13] = new DateTime(1975, 5, 2);
        birth[14] = new DateTime(1945, 15, 3);
        birth[15] = new DateTime(1969, 14, 6);
        birth[16] = new DateTime(1987, 141, 4);
        birth[17] = new DateTime(1976, 23, 5);
        birth[18] = new DateTime(1989, 28, 6);
        birth[19] = new DateTime(1988, 23, 9);

        // Populate Array Person[] People = new Person[20];     


        for (int i = 0; i < People.Length; i++)
        {
            People[i]= new Person(first[i], last[i], birth[i]);
        }

私のクラスはこんな感じ

public class Person
{
    private string _firstname;
    private string _lastname;
    private DateTime _birthDate;

    public void Personn(string firstname, string lastname, DateTime birthDate)
    {
        _firstname = firstname;
        _lastname = lastname;
        _birthDate = birthDate;
    }

    public string Firstname
    { get { return _firstname; } }

    public string Lastname
    { get { return _lastname; } }

    public DateTime Birthdate
    { get { return _birthDate; } }
}
4

5 に答える 5

4

それ以外の

 public void Personn(string firstname, string lastname, DateTime birthDate)

使用する

 public Person(string firstname, string lastname, DateTime birthDate)
于 2012-06-04T09:34:02.137 に答える
2

あなたがコンストラクターだと思っているのは単なるメソッドです。クラス名のつづりが間違っています。

これを変える:

    public void Personn(string firstname, string lastname, DateTime birthDate)

に:

    public Person(string firstname, string lastname, DateTime birthDate)
于 2012-06-04T09:34:32.950 に答える
0

コンストラクターを確認してください。戻り値の型を持たず、クラスと同じ名前にする必要があります。

于 2012-06-04T09:34:54.890 に答える
0

この行の代わりに使用する必要があると思います:

 public void Personn(string firstname, string lastname, DateTime birthDate)

これです:

 public Person(string firstname, string lastname, DateTime birthDate)

現在はコンストラクターではなく void メソッドであるため、この場合はパラメーターを持たないデフォルトのコンストラクターがあります。それはあなたの問題の理由かもしれません!

アンドリュー

于 2012-06-04T09:37:00.327 に答える
0

コンストラクターには戻り値の型がありません。voidコンストラクターから削除します。

于 2012-06-04T09:38:34.297 に答える