2012-04-10 18 views
-1

Ich erstelle einen Konstruktor, der alle Variablen aus einer anderen Klasse abrufen muss. Im Moment habe ich:Erstellen eines Objekts mit statischen Membern aus einer Klasse

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; 
} 

Die Variablen in der Address.AddressDetails sind alle auch statisch. Wie stelle ich Person.Address alle Variablen in der AddressDetails-Klasse dar?

+1

Warum Sie mit einem regelmäßigen Konstruktor alle statischen Felder in Kombination sind zu vergeben? –

+0

Mit all diesen statischen öffentlichen Feldern ist sehr schlechtes Design. Sie werden über alle Instanzen von 'Person' verteilt - was ist der Grund dafür? – Oded

+0

Und das Kopieren von anderen statischen Feldern ist auch etwas komisch. –

Antwort

-1

im Konstruktor:

{ 
    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;  

} 

Etwas Ähnliches.

  • machen ein static public Methode einen Wert
  • machen alle Mitglieder der Klasse private
+0

@ downvoter: vorsichtig erklären? – Tigran

Verwandte Themen