-1

我正在创建一个构造函数,它需要从另一个类中获取所有变量。目前我有:

public class Person 
{
    public Person(Address.AddressDetails newAddress , string newTitle, string      newForname, string newSurname, string newTel,
                        string newMob, string newEmail)
        {
        }
        static public int ID;
        static public string Title;
        static public string Decorations;
        static public string Forename;
        static public string Surname;
        static public string Telephone;
        static public string Mobile;
        static public string Email;
        static public Address.AddressDetails Address;
}

Address.AddressDetails 中的变量也是静态的。如何让 Person.Address 表示 AddressDetails 类中的所有变量?

4

2 回答 2

-1

在构造函数中:

{
    Person.Adress = newAdress;
}
于 2012-04-10T09:51:52.200 回答
-1
public class Person 
{
     public static Assign(Address.AddressDetails newAddress , string newTitle, string      newForname, string newSurname, string newTel,
                        string newMob, string newEmail) 
    {
        Address = newAddress;
        Email = newEmail;
        ....
        ... 

    }

     static private int ID;
     static private string Title;
     static private string Decorations;
     static private string Forename;
     static private string Surname;
     static private string Telephone;
     static private string Mobile;
     static private string Email;
     static private Address.AddressDetails Address;    

}

像这样的东西。

  • 制作一个static public赋值的方法
  • 使班级的所有成员private
于 2012-04-10T09:55:18.343 回答