Autor Beitrag
DennisXX
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 133



BeitragVerfasst: Di 23.08.11 09:27 
Hallo zusammen !

Weiß jemand von euch, wie ich in C Sharp eine Codezeile, die im Visual Studio waagerecht zu lang ist, mit einem Zeilenumbruch versehen kann, ohne dass die IDE mir eine Fehlermeldung ausgibt?

Viele Grüße
Dennis
vagtler
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 96
Erhaltene Danke: 24


Delphi 2010, C# (VS 2012), Objective-C, Java
BeitragVerfasst: Di 23.08.11 09:33 
Enter drücken.

Für diesen Beitrag haben gedankt: BenBE, Regan, stes, Xcalibur
bakachan
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 503
Erhaltene Danke: 34

W7 (x64) Ultimate
C# / VB.NET (VS2010 Ultimate)
BeitragVerfasst: Di 23.08.11 09:42 
C# schließt die Codezeile mit einem Semikolon
es ist also kein Problem einfach sowas zu schreiben:
ausblenden C#-Quelltext
1:
2:
int myIntVar=
42;


Was nicht so einfach funktioniert ist ein String über mehrere Zeilen:
ausblenden C#-Quelltext
1:
2:
string myString="Bla
Neue Zeile"
;


Das muss dann so aussehen:
ausblenden C#-Quelltext
1:
2:
string myString="Bla"+
"Neue Zeile";


Wenn du den Zeilenumbruch im Text selbst haben möchtest kannst du einfach ein Environment.NewLine einfügen
ausblenden C#-Quelltext
1:
2:
string myString="Bla"+Environment.NewLine+
"Neue Zeile";

Für diesen Beitrag haben gedankt: BenBE
DennisXX Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 133



BeitragVerfasst: Di 23.08.11 10:07 
Und wie genau gestaltet sich das, wenn das in einer Methodendefinition bei den Übergabeparametern erfolgt?

Grüße
Dennis
Th69
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Moderator
Beiträge: 4796
Erhaltene Danke: 1059

Win10
C#, C++ (VS 2017/19/22)
BeitragVerfasst: Di 23.08.11 10:26 
Hallo Dennis,

könntest du bitte deine Frage ein wenig mehr spezifizieren? Gib doch einfach mal ein Code-Beispiel an.

Und bzgl. Strings und Zeilenumbrüche: man kann auch das @-Zeichen benutzen, um einen String in "Reinform" zu erhalten (d.h. alle Steuerzeichen werden ignoriert):
ausblenden C#-Quelltext
1:
2:
string s = @"Hallo 
World mit einem Backslash \!"
;
DennisXX Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 133



BeitragVerfasst: Di 23.08.11 11:57 
Hier ein Codebeispiel:

ausblenden C#-Quelltext
1:
2:
3:
4:
5:
public void createFunction(string eins, string zwei, int zahl1, int zahl2, int zahl3, int zahl4){

   //irgendwelcher Code

}


Ich möchte nun erreichen, dass man die Parameter untereinander im Quellcode setzt also so:

ausblenden C#-Quelltext
1:
2:
3:
4:
5:
6:
public void createFunction(string eins, string zwei, int zahl1, 
                           int zahl2, int zahl3, int zahl4){

   //irgendwelcher Code

}


Wie kann ich das in C# machen?

Grüße
Dennis
Kha
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 3803
Erhaltene Danke: 176

Arch Linux
Python, C, C++ (vim)
BeitragVerfasst: Di 23.08.11 12:05 
Du solltest aus unseren Beiträgen langsam herausgelesen haben, dass das überhaupt kein Problem ist. Ohne Fehlermeldung werden wir hier nicht weiter kommen.

_________________
>λ=
bakachan
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 503
Erhaltene Danke: 34

W7 (x64) Ultimate
C# / VB.NET (VS2010 Ultimate)
BeitragVerfasst: Di 23.08.11 12:06 
Dein Beispiel funktioniert doch sogar...
stes
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 36
Erhaltene Danke: 6

Win 95, Win XP, Win 7 64-bit
C# (VS 2010, #Develop), Java (eclipse)
BeitragVerfasst: Di 23.08.11 12:45 
Zitat:
Ohne Fehlermeldung werden wir hier nicht weiter kommen.


Wenn er alles so gemacht hat wie im Beispiel werden wir die wohl nicht mehr zu sehen bekommen xD

_________________
"Das Internet ist ein großer Misthaufen, in dem man allerdings auch kleine Schätze und Perlen finden kann." Joseph Weizenbaum