.NET: String Format Characters

C or c: currency based on local cultural symbol, $1234.56
D or d: decimal, optional number (i.e. {0:D8}) used to pad value, 012345678
E or e: exponential notation, 1.234E+05
F or f: fixed point, 0:F3 1234.567
G or g: general, used to format to fixed or exponential
N or n: numerical format (with commas), 1,234.00
X or x: hexadecimal, 0:X 123F, 0:x 123f

You can use this with string.Format, like below:

C#: default constructor

Default constructor ensures that all member data is set to a default value (all constructors do this).

Once you define a custom constructor, the free default constructor is removed. You must redefine it if you want to be able to create objects using it.

C#: creating objects, new keyword

You can’t allocate classes on the stack in C#, unlike C++.

The new keyword calculates the number of bytes needed for the specified object and allocates enough memory from the managed heap.

C# object variables are a reference to the object in memory, not the object itself.

C#: System.Environment

Here are a few handy properties and methods that are found on the System.Environment class:

Current OS: System.Environment.OSVersion

Current working directory: System.Environment.CurrentDirectory

string[] of drives on the machine: System.Environment.GetLogicalDrives()

Version of .NET app is running under: System.Environment.Version

Current machine name: System.Environment.MachineName

Newline symbol for the current environment: System.Environment.NewLine

Number of processors on the current machine: System.Environment.ProcessorCount

Full path to system directory: System.Environment.SystemDirectory

User name application is running under: System.Environment.UserName

C#: Variations on the Main() method, System.Environment.GetCommandLineArgs()

Below are a few different variations that can be done on the Main method.

Return type is void, string array as argument:

Return type is void, no arguments:

Return type is int, no arguments:

Return type is int, string array as argument:

Besides accessing them via the ‘string[] args’ parameter, you can access command-line arguments using

When you do this, you are not required to define the Main() method as taking a string array.

.NET: csc.exe, cordbg.exe

csc.exe /target:winexe – prevents a console window from appearing in the background

cordbg.exe assemblyloads .pdb file

b: set or display breakpoints
del: remove one or more breakpoints
g: continue debugging
p: print all loaded variables
o: step out of the current function
si: step into the next line
so: step over the next line
ex: exit the debugger

.NET: CLS (Common Language Specification), CLR (Common Language Runtime), using keyword

CLS: “common language specification”, set of rules that describe what features a .NET-aware compiler must support to produce code that can be hosted by the CLR. It’s a subset of the full functionality defined by the CTS (common type specification).

CLR: “common language runtime”, mscoree.dll:

  1. resolves the location of an assembly
  2. finds the requested type in the binary (by reading metadata)
  3. lays out the type in memory
  4. compiles associated CIL into platform specific instructions
  5. performs security checks
  6. executes the code

Using keyword is just shorthand notation, using it or the fully qualified name has no effect on performance or the size of the assembly. CIL code always uses fully qualified names.

CLI: “common language infrastructure”, ecma spec, describes executable code and runtime environment for .NET

.NET: CTS (Common Type System), type, sealed class, interface, abstract class, structs vs classes, enumeration, delegates, built-in data types

type: generic term used to refer to: class, structure, interface, enumeration, delegate.

type member: constructor, finalizer, static constructor, nested type, operator, method, property, indexer, field, read only field, constant, event.

static members are bound at the class level, instance members are bound at the object level.

sealed class: cannot function as a base class to other classes

interface: collection of abstract members that provide a contract between the object and object user. Only members may exist, no implementation. A given class may implement any number of interfaces.

abstract class: can’t instantiate, used to define common behavior for derived types, can have implementation.

structs are value-types. classes are reference-types.

interfaces do not derive from a common base interface like IUnknown.

enumerations derive from System.Enum and by default the storage used to hold them is a32-bit integer.

delegates are the same as a type-safe C-style function pointer. They derive fromSystem.MulticastDelegate.

.NET built in data types (intrinsic CTS data types):

CTS Data Type, C# Keyword, C++ Keyword

System.Byte, byte, unsigned char
System.SByte, sbyte, signed char
System.Int16, short, short
System.Int32, int, int or long
System.Int64, long, __int64
System.UInt16, ushort, unsigned short
System.UInt32, uint, unsigned int or unsigned long
System.UInt64, ulong, unsigned __int64
System.Single, float, Float
System.Double, double, Double
System.Object, object, Object^
System.Char, char, wchar_t
System.String, string, String^
System.Decimal, decimal, Decimal
System.Boolean, bool, Bool