Zum Inhalt springen
View in the app

A better way to browse. Learn more.

Fachinformatiker.de

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

C# mehrere Instanzen einer Klasse

Empfohlene Antworten

Veröffentlicht

Hi,

wie kann ich in C# mehrere Instanzen einer Klasse erstellen ?

In Delphi, womit ich sonst programmiere, sieht das folgendermaßen aus:

Ich nutze eine Klasse "TPerson", und erstelle mir im FormCreate daraus 10 Instanzen.


var

  Form1: TForm1;

  person: array[1..10] of TPerson;


procedure TForm1.FormCreate(Sender: TObject);

var

  i:integer;

begin

  for i := 1 to 10 do begin

    person[i] := TPerson.Create;

  end;

  dsInit;

  dsAnzeigen;

  Geaendert := False;

end;

Wie würde dieses Beispiel in C# aussehen ?

Danke im Voraus!

Hallo,

man kann dies in einer generischen Liste tun und dann wieder auf die Inhalte der Liste zugreifen.


        private void Form1_Load(object sender, EventArgs e)

        {

            List<TextBox> list = new List<TextBox>();

            while (list.Count() <= 10)

            {

                list.Add(new TextBox());

            }

        }

Danach kannst Du die Liste (typensicher) durchlaufen oder eien bestimmten Index abrufen.

Wozu benötigst Du das denn? Oder ist das nur eine theoretische Anforderung?

Gruß,

Thomas

  • Autor

Ach ich brauche das für eine Berufsschulaufgabe im Fach Anwendungsentwicklung. Da ich im Betrieb mit Delphi arbeite und wir in der Schule mit C# programmieren gibts da für mich manchmal solche Stolperstellen :)

Danke für die Hilfe.

Archiv

Dieses Thema wurde archiviert und kann nicht mehr beantwortet werden.

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.