C#: Ist es möglich "formübergreifende" Variabeln zu erstellen?
Danke im Vorraus...
1 Antwort
![](https://images.gutefrage.net/media/user/DataJockey/1444745439_nmmslarge.jpg?v=1444745439000)
ja, dein Formular ist nichts weiter als eine Klasse. Darin kannst du eine statitc-public-Variable erstellen, ..welche du in jeder anderen Klasse deines Namesspace benutzen kannst.
z.B. Deklaration in Klasse MyClass
public static int MyInt = 20;
Aufruf
MyClass.MyInt = 30;
int otherInt = 12 + MyClass.MyInt;
das geht natürlich auch als nicht static. Dann brauchst du aber eine Instanz deiner Klasse.
viel Erfolg, dj
![](https://images.gutefrage.net/media/user/DataJockey/1444745439_nmmslarge.jpg?v=1444745439000)
DataJockey
11.05.2016, 10:58
![](https://images.gutefrage.net/media/default/user/6_nmmslarge.png?v=1438863662000)
@DataJockey
Ich versteh' deine Methode nicht richtig... Kannst du mir das bitte erklären?
Hab das jetzt erstmal mit externen Dateien gelöst.