C Sharp: Difference between revisions
From Wildsong
Jump to navigationJump to search
Brian Wilson (talk | contribs) |
Brian Wilson (talk | contribs) mNo edit summary |
||
Line 1: | Line 1: | ||
I wanted this page to be called C# but apparently mediawiki did not approve. | I wanted this page to be called C# but apparently mediawiki did not approve. | ||
Oh well. Maybe I will put all things beginning with the letter 'c' here. | Oh well. Maybe I will put all things beginning with the letter 'c' here. | ||
== readonly == | |||
Yes, there is a readonly setting for variables. One would think 'const' would be enough. | |||
Aren't these the same? | |||
public static readonly string foo = "I am read - only."; // happens at program load | |||
public const string foo = "I am read - only"; // happens at compile time | |||
but actually you can do this | |||
public static readonly string foo = new some_initializer(); | |||
so the value is set once, and it's done atomically so it is thread-safe. | |||
== Preprocessor Directives == | == Preprocessor Directives == |
Revision as of 19:50, 23 May 2012
I wanted this page to be called C# but apparently mediawiki did not approve. Oh well. Maybe I will put all things beginning with the letter 'c' here.
readonly
Yes, there is a readonly setting for variables. One would think 'const' would be enough. Aren't these the same?
public static readonly string foo = "I am read - only."; // happens at program load public const string foo = "I am read - only"; // happens at compile time
but actually you can do this
public static readonly string foo = new some_initializer();
so the value is set once, and it's done atomically so it is thread-safe.
Preprocessor Directives
#if DEBUG http://codeidol.com/csharp/essential-csharp/Operators-and-Control-Flow/Csharp-Preprocessor-Directives/ #endif
What about things in square brackets
That I can't type in a wiki, like "bracket CommandLine bracket"
When would I ever use a Struct?
Read the official documentation here.