I'm wondering about instances when it makes sent to use #define and #if statements. I've known about it for a while, but never incorporated it into my way of coding. How exactly does this affect the compilation?
Is #define the only thing that determines if the code is included when compiled? If I have #define DEBUGme as a custom symbol, the only way to exclude it from compile is to remove this #define statement?
Use a semicolon to join two related independent clauses in place of a comma and a coordinating conjunction (and, but, or, nor, for, so, yet). Make sure when you use the semicolon that the connection between the two independent clauses is clear without the coordinating conjunction.
Colons (:) are used in sentences to show that something is following, like a quotation, example, or list. Semicolons (;) are used to join two independent clauses, or two complete thoughts that could stand alone as complete sentences.
When a comma separates two complete sentences joined by a conjunction (and, but, or, nor, for, so, or yet) the comma and the conjunction can be replaced with a semicolon. I ate dinner, and I went to the movies. = I ate dinner; I went to the movies. She finished top of her class, but she was struggling to find work.
Use dashes to mark the beginning and end of a series, which might otherwise get confused, with the rest of the sentence: Example: The three female characters—the wife, the nun, and the jockey—are the incarnation of excellence. Dashes are also used to mark the interruption of a sentence in dialogue: Example: “Help!
In C# #define
macros, like some of Bernard's examples, are not allowed. The only common use of #define
/#if
s in C# is for adding optional debug only code. For example:
static void Main(string[] args)
{
#if DEBUG
//this only compiles if in DEBUG
Console.WriteLine("DEBUG")
#endif
#if !DEBUG
//this only compiles if not in DEBUG
Console.WriteLine("RELEASE")
#endif
//This always compiles
Console.ReadLine()
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With