使用类中的静态成员创建对象

时间:2012-04-10 09:48:13

标签: c# class constructor

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

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类中的所有变量?

2 个答案:

答案 0 :(得分:-1)

在构造函数中:

{
    Person.Adress = newAdress;
}

答案 1 :(得分:-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
  • 的所有成员