-1

How i can create hidden methods in C#?

For sample:

The class library should only include methods in the release that are publicly available to read a file. In the debug or developer build there should also exist methods and classes to write these files.

How can I define in a release build that some methods are not compiled?

Adrian Preuss
  • 3,228
  • 1
  • 23
  • 43
  • [Does this answer your question?](https://stackoverflow.com/questions/5080477/debug-only-code-that-should-run-only-when-turned-on) – ProgrammingLlama Nov 22 '20 at 08:50
  • 1
    https://learn.microsoft.com/en-us/dotnet/csharp/language-reference/preprocessor-directives/preprocessor-if – TheGeneral Nov 22 '20 at 08:52
  • 1
    Does this answer your question? ["Debug only" code that should run only when "turned on"](https://stackoverflow.com/questions/5080477/debug-only-code-that-should-run-only-when-turned-on) – Frederik Hoeft Nov 22 '20 at 09:04
  • `[Conditional("DEBUG")]` as answer is not the option for the simple question – Adrian Preuss Nov 22 '20 at 09:46

1 Answers1

4

You can use the if debug statement

#if DEBUG
    Console.WriteLine("Debug version");
#endif

Whatever is defined in between, will only be included in the debug build and excluded in the release build. You will not even find it by dissasembling the code.

There are other definitions that can be used and even custom ones.

Athanasios Kataras
  • 25,191
  • 4
  • 32
  • 61