All notes
Csharp

Intro

Build and run

After installing .net framework, the command "csc" is located under:

c:\Windows\Microsoft.NET\Framework\vX.X.XXX Should contain the latest
32 bit version of csc.exe
c:\Windows\Microsoft.NET\Framework64\vX.X.XXX Should contain the
lastest 64 bit version of csc.exe

Or you could find this by search in regedit: HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\NET Framework Setup\NDP.

CLR

The Common Language Runtime (CLR), the virtual machine component of Microsoft's .NET framework, manages the execution of .NET programs.

Basic

COM

wikipedia: COM.

Component Object Model (COM) is a binary-interface standard for software components introduced by Microsoft in 1993. It is used to enable inter-process communication and dynamic object creation in a large range of programming languages. COM is the basis for several other Microsoft technologies and frameworks, including OLE, OLE Automation, ActiveX, COM+, DCOM, the Windows shell, DirectX, UMDF and Windows Runtime.

Value and Reference Types

When a variable is declared using one of the basic, built-in data types or a structure, it is a value type. An exception is the string data type, which is a reference type.

A value type stores its contents in memory allocated on the stack. Using the stack is efficient, but the limited lifetime of value types makes them less suited for sharing data between different classes.

A value type is derived from System.ValueType. It can't be used as base class.

In contrast, a reference type, such as an instance of a class or an array, is allocated in a different area of memory - the heap.

It's only reclaimed when C#'s garbage collection system determines it is no longer needed.


int[] numbers = new int[10];

In c++, the value and reference is determined by class user; In c#, it is determined by class definer.

Delegate and Events

Delegation is like function pointer in C++, but is type-safe. Events is based on delegation.

JIT

Thread

Library References

Using statement

MSDN: Avoiding Problems with the Using Statement.

The C# "using" statement results in a call to Dispose(). This is the same as Close(), which may throw exceptions when a network error occurs. The call to Dispose() happens implicitly at the closing brace of the "using" block.

DateTime


DateTime.Now.ToString("yyyyMMdd.HHmmss");
// 20160614.154028

FAQ

Bitwise operations


Console.WriteLine((1<<16).ToString()); // Output: 65536
Console.WriteLine((16<<1).ToString()); // Output: 32
Console.WriteLine((2<<8).ToString()); // Output: 512

Resx files

MSDN: .resx file.

The .resx resource file format consists of XML entries, which specify objects and strings inside XML tags.

When viewing a .resx file, you can actually see the binary form of an embedded object (for example, a picture) when this binary information is a part of the resource manifest.

Why c# has no with statement

StackOverflow: with block equivalent in c sharp.

Actually extra code-blocks like that are very handy if you want to re-use variable names:


{
    var where = new MyObject();
    where.property = "xxx";
    where.SomeFunction("yyy");
}

{
    var where = new MyObject();
    where.property = "zzz";
    where.SomeFunction("uuu");
}

Python has "with" statement because Python has no curlies (such as {}) for code blocks!

Server side of automation of Office

Microsoft Support: Considerations for server-side Automation of Office.

Problems using server-side Automation of Office:

Alternatives to server-side Automation: