2012-04-10 9 views
-1

私は別のクラスからすべての変数を取得する必要があるコンストラクタを作成しています。現時点では、私は持っています:クラスの静的メンバーを使用してオブジェクトを作成する

Address.AddressDetailsの変数もすべて静的です。 Person.AddressをAddressDetailsクラスのすべての変数を表すようにするにはどうすればよいですか?コンストラクタで

+1

は、なぜあなたは、通常のコンストラクタとの組み合わせですべての静的フィールドを使用していますか?作る値

  • を割り当てるstatic public方法を作りますか –

  • +0

    これらのすべての静的パブリックフィールドを持つことは非常に悪い設計です。それらは 'Person'のすべてのインスタンスにわたって共有されます - これはなぜですか? – Oded

    +0

    他の静的フィールドからコピーするのも奇妙です。 –

    答えて

    -1

    { 
        Person.Adress = newAdress; 
    } 
    
    -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;  
    
    } 
    

    このような何か。

    • クラスのすべてのメンバーprivate
    +0

    @downvoter:説明してください。 – Tigran

    関連する問題