csc -out:My.exe File.cs -> Compiles File.cs and creates My.exe
csc -define:DEBUG -optimize -out:File2.exe *.cs -> Compiles all the C# files in the current directory with optimizations enabled and defines the DEBUG symbol. The output is File2.exe
csc -target:library -out:File2.dll -warn:0 -nologo -debug *.cs -> Compiles all the C# files in the current directory producing a debug version of File2.dll. No logo and no warnings are displayed
csc -target:library -out:Something.xyz *.cs -> Compiles all the C# files in the current directory to Something.xyz (a DLL)
8.1 Compiler Options Listed
Option Purpose
@ Reads a response file for more options.
-? Displays a usage message to stdout.
-additionalfile Names additional files that don't directly affect code generation but may be used by analyzers for producing errors or warnings.
-addmodule Links the specified modules into this assembly
-analyzer Run the analyzers from this assembly (Short form: -a)
-appconfig Specifies the location of app.config at assembly binding time.
-baseaddress Specifies the base address for the library to be built.
-bugreport Creates a 'Bug Report' file. This file will be sent together with any crash information if it is used with -errorreport:prompt or -errorreport:send.
-checked Causes the compiler to generate overflow checks.
-checksumalgorithm:<alg> Specifies the algorithm for calculating the source file checksum stored in PDB. Supported values are: SHA1 (default) or SHA256.
-codepage Specifies the codepage to use when opening source files.
-debug Emits debugging information.
-define Defines conditional compilation symbols.
-delaysign Delay-signs the assembly by using only the public part of the strong name key.
-deterministic Causes the compiler to output an assembly whose binary content is identical across compilations if inputs are identical.
-doc Specifies an XML Documentation file to generate.
-errorreport Specifies how to handle internal compiler errors: prompt, send, or none. The default is none.
-filealign Specifies the alignment used for output file sections.
-fullpaths Causes the compiler to generate fully qualified paths.
-help Displays a usage message to stdout.
-highentropyva Specifies that high entropy ASLR is supported.
-keycontainer Specifies a strong name key container.
-keyfile Specifies a strong name key file.
-langversion:<string> Specify language version: Default, ISO-1, ISO-2, 3, 4, 5, 6, 7, 7.1, 7.2, 7.3, or Latest
-lib Specifies additional directories in which to search for references.
-link Makes COM type information in specified assemblies available to the project.
-linkresource Links the specified resource to this assembly.
-main Specifies the type that contains the entry point (ignore all other possible entry points).
-moduleassemblyname Specifies an assembly whose non-public types a .netmodule can access.
-modulename:<string> Specify the name of the source module.
-noconfig Instructs the compiler not to auto include CSC.RSP file.
-nologo Suppresses compiler copyright message.
-nostdlib Instructs the compiler not to reference standard library (mscorlib.dll).
-nowarn Disables specific warning messages
-nowin32manifest Instructs the compiler not to embed an application manifest in the executable file.
-optimize Enables/disables optimizations.
-out Specifies the output file name (default: base name of file with main class or first file).
-parallel[+|-] Specifies whether to use concurrent build (+).
-pathmap Specifies a mapping for source path names output by the compiler.
-pdb Specifies the file name and location of the .pdb file.
-platform Limits which platforms this code can run on: x86, Itanium, x64, anycpu, or anycpu32bitpreferred. The default is anycpu.
-preferreduilang Specifies the language to be used for compiler output.
-publicsign Apply a public key without signing the assembly, but set the bit in the assembly indicating the assembly is signed.
-recurse Includes all files in the current directory and subdirectories according to the wildcard specifications.
-reference References metadata from the specified assembly files.
-refout Generate a reference assembly in addition to the primary assembly.
-refonly Generate a reference assembly instead of a primary assembly.
-resource Embeds the specified resource.
-ruleset:<file> Specify a ruleset file that disables specific diagnostics.
-subsystemversion Specifies the minimum version of the subsystem that the executable file can use.
-target Specifies the format of the output file by using one of four options: -target:appcontainerexe, -target:exe, -target:library, -target:module, -target:winexe, -target:winmdobj.
-unsafe Allows unsafe code.
-utf8output Outputs compiler messages in UTF-8 encoding.
-warn Sets the warning level (0-4).
-warnaserror Reports specific warnings as errors.
-win32icon Uses this icon for the output.
-win32manifest Specifies a custom win32 manifest file.
-win32res Specifies the win32 resource file (.res).
9. Control flow statements
9.1 Switch
switch (expression) {
//expression may be integer, string or enum
case expression:
//statements
break/ goto / return()
case ..
default
//statements
break/ goto / return()
}
9.2 If
if (condition) {
//statements
} else {
//statements
}
10. Loop
10.1 While
while (condition) {body}
10.2 Do while
do {body} while condition;
10.3 For
for (initializer; termination condition; iteration;) {
//statements
}
10.4 For each
foreach (type identifier in collection) {
//statements
}
11. Class Definition
11.1 Class
public | protected | internal | private
abstract | sealed | static
class className [:class/interfaces inherited from]
To pass a parameter by reference with the intent of changing the value, use the ref, or out keyword. To pass by reference with the intent of avoiding copying but not changing the value, use the in modifier
11.4 Property
[modifier] <dataType> property name{
public string BrandName
{
get { return brandName; }
set { brandName = value; }
}
}
12. Struct
12.1 Defining a structure
[attribute][modifier] struct name [:interfaces] { struct-body }
12.2 Class vs Structure
-> Classes are reference types and structs are value types
-> Structures do not support inheritance
-> Structures cannot have default constructor
13. Enum
13.1 Declaring enum variable
enum <enumName> {
enumeration list
};
enumName - Specifies the enumeration type name
enumeration list is a comma-separated list of identifiers
//Each of the symbols in the enumeration list stands for an integer value, one greater than the symbol that precedes it.
14. Delegates
//A delegate is a reference type variable that holds the reference to a method. The reference can be changed at runtime.
14.1 Declaring delegates
//Delegate declaration determines the methods that can be referenced by the delegate.