Autor Beitrag
Oliver M.
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 109
Erhaltene Danke: 1

Win 8 CP
VS 11 Beta
BeitragVerfasst: Sa 09.07.11 19:49 
Ich habe ein Stück Code (C-Sharp) das nur im Programm sein soll, wenn ich Debug ausgewählt habe, nicht aber wenn ich Release ausgewählt habe.

Also folgendes habe ich schon mal herausgefunden:
ausblenden C#-Quelltext
1:
2:
3:
#if ???
Code
#endif

Aber was muss bei ??? hin?

Ich hoffe ihr könnt mir helfen,
Oliver
Flitzs
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 123
Erhaltene Danke: 7

Win7 x64/86 WinServer 2008 R2 x64
C#/C++/C VS2010
BeitragVerfasst: Sa 09.07.11 20:10 
Das kommt darauf an, was vorher definiert wurde. Du kannst VS so einstellen, dass es die DEBUG-Konstante selbst definiert (Projekt => <Name>-Eigenschaften => Erstellen).

lg Flitzs
Christian S.
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 20451
Erhaltene Danke: 2264

Win 10
C# (VS 2019)
BeitragVerfasst: Sa 09.07.11 20:14 
Ist AFAIK sogar standardmäßig so eingestellt: Im Debug-Modus ist die DEBUG-Konstante definiert.

_________________
Zwei Worte werden Dir im Leben viele Türen öffnen - "ziehen" und "drücken".
Oliver M. Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 109
Erhaltene Danke: 1

Win 8 CP
VS 11 Beta
BeitragVerfasst: Sa 09.07.11 20:16 
Ne, das ist nicht was ich meine:

Ich habe eine MessageBox, die mir Informationen über das laufende Programm giebt, die zum Debugen notwendig sind. Doch im Release soll man diese MessageBox nicht sehen.

Man kann dem Kompiler sagen, dass er den Code nur mitkompileren soll, wenn die Bedingung stimmt:
ausblenden C#-Quelltext
1:
2:
3:
#if a == b
messageBox.Show();
#endif


Doch was muss ich als Bedingung angeben???

Ich hoffe ihr versteht mich,
Oliver
Christian S.
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 20451
Erhaltene Danke: 2264

Win 10
C# (VS 2019)
BeitragVerfasst: Sa 09.07.11 20:17 
ausblenden C#-Quelltext
1:
2:
3:
#if DEBUG
messageBox.Show();
#endif

_________________
Zwei Worte werden Dir im Leben viele Türen öffnen - "ziehen" und "drücken".

Für diesen Beitrag haben gedankt: Oliver M.
Oliver M. Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 109
Erhaltene Danke: 1

Win 8 CP
VS 11 Beta
BeitragVerfasst: Sa 09.07.11 20:22 
:think:
Ah, das macht Sinn...
Danke
Oliver
gfoidl
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 157
Erhaltene Danke: 19

Win XP
C#, Fortran 95 - Visual Studio
BeitragVerfasst: Sa 09.07.11 22:03 
Hallo,

schau dir in diesem Zusammenhang auch das ConditionalAttribute an.

mfG Gü

_________________
Alle sagten, das geht nicht! Dann kam einer, der wusste das nicht - und hat's gemacht!