1

imagine the following code in VB.NET:

#Const TestCode = True
#If TestCode Then
  Console.WriteLine("Test code enabled.")
#Else
  Console.WriteLine("No test code.")
#End If

These conditions are executed in compilation time, but now I'm trying to give to the constant TestCode a value from a file or a database. The idea is to be able to change that constant value in run-time without the need of updating the software in production.

Anyone knows how to do that?

Thanks

Daniel Serrão
  • 481
  • 1
  • 6
  • 17
  • 1
    A `Const` is constant (and `#Const` is not quite the same - it is for compiling different versions/flavors). You cant assign it from a variable. You *can* use something other than a Bool to define different DBs or whatever – Ňɏssa Pøngjǣrdenlarp Jun 28 '16 at 18:25

1 Answers1

1

#if conditionally compiles the contained block of code, so if TestCode = True, then Console.WriteLine("No test code.") is not even compiled. There would be no way to "switch over to it" at runtime because that line of code would not exist in the application binary. Why not just use a regular if instead of compiler directives?

Paul Abbott
  • 7,065
  • 3
  • 27
  • 45