.NET Framework
包含了一個巨大的代碼庫, 其包含了不同的塊, 可以方便的調用
*****************************************************************************************************************************************************************************************
公共語言運行庫 (common language runtime,CLR) 託管代碼執行核心中的引擎。運行庫爲託管代碼提供各種服務,如跨語言集成、代碼訪問安全性、對象生存期管理、調試和分析支持。
公共語言運行庫自動處理對象佈局並管理對象引用,當不再使用對象時釋放它們。按這種方式實現生存期管理的對象稱爲託管數據。
有了公共語言運行庫,就可以很容易地設計出對象能夠跨語言交互的組件和應用程序。也就是說,用不同語言編寫的對象可以互相通信,並且它們的行爲可以緊密集成。
*****************************************************************************************************************************************************************************************
CLR(Common Intermediate Language) && JIT (Just-In-Time)
CLR(通用中間語言): 在使用.net framework 中的代碼進行編譯時, 會將其編譯爲CLR,它是一種中間語言 並非專門用於一種操作系統
JIT() 將CLR 編譯成 當前 OS 可以識別的代碼
****************************************************************************************************************************************************************************************
內存中的 堆棧
要點:
堆:順序隨意
棧:先進後出
值類型通常被分配在棧上,它的變量直接包含變量的實例,使用效率比較高。
引用類型分配在託管堆上,引用類型的變量通常包含一個指向實例的指針,變量通過該指針來引用實例。
堆和棧的區別
一、預備知識—程序的內存分配
一個編譯的程序佔用的內存分爲以下幾個部分
1、棧區(stack)— 由編譯器自動分配釋放 ,存放函數的參數值,局部變量的值等。其操作方式類似於數據結構中的棧。
2、堆區(heap) — 一般由程序員分配釋放, 若程序員不釋放,程序結束時可能由OS回收 。注意它與數據結構中的堆是兩回事,分配方式倒是類似於鏈表,呵呵。
3、全局區(靜態區)(static)—,全局變量和靜態變量的存儲是放在一塊的,初始化的全局變量和靜態變量在一塊區域, 未初始化的全局變量和未初始化的靜態變量在相鄰的另一塊區域。 - 程序結束後有系統釋放
4、文字常量區 —常量字符串就是放在這裏的。 程序結束後由系統釋放
5、程序代碼區—存放函數體的二進制代碼。
值類型的內存不由GC(垃圾回收,Gabage Collection)控制,作用域結束時,值類型會自行釋放,減少了託管堆的壓力,因此具有性能上的優勢。例如,通常struct比class更高效;而引用類型的內存回收,由GC來完成,微軟甚至建議用戶最好不要自行釋放內存。
********************************************************************************************************************************************************************************
ASP.NET Page的生命週期
http://msdn.microsoft.com/en-us/library/ms178472.aspx
********************************************************************************************************************************************************************************
C#中 變量的作用域
class valuescope{
static int t = 33;
public static void Main()
{
int t = 66;
Console.WriteLine(t);
Console.WriteLine(valuescope.t);
}
}
Output:
66
33
*********************************************************************************************************************************************************************************
C#中的預處理指令 (Preprocessor)
例如: #if #else #endif #region #endregion
預處理指令專門用於debug, 不會被compiler進行編譯
***********************************************************************************************************************************************************************************
C#中的Hashtable的使用
using System.Collections;
Hashtable ht = new Hashtable();
ht.Add("txt", "notepad.exe");
ht.Add("bmp", "paint.exe");
ht.Add("dib", "paint.exe");
ht.Add("rtf", "wordpad.exe");
Console.WriteLine(ht["dib"]);
output: "paint.exe"
**************************************************************************************************************************************************************************************
What’s the difference betweenSystem.String
and System.Text.StringBuilderclasses?
System.String
is immutable(不可改變的).
System.StringBuilder was designed with the purpose of having a mutable string where a variety of operations
can be performed.
StringBuilder is more efficient in
cases where there is a large amount of string manipulation. Strings are immutable, so each time a string is changed, a new instance in memory is created.
string一旦形成對象後就只有可讀性,如果想修改 則需重新實例化對象
每次改變string時,多要在內存中實例化一次,所以比stringbuilder耗費內存資源
*****************************************************************************************************************
What’s
the difference between the System.Array.CopyTo()
and System.Array.Clone()?
The
Clone() method returns a new array (a shallow copy) object containing all the elements in the original array. The CopyTo() method copies the elements into another existing array.
*****************************************************************************************************************
String 和 string 的區別
兩者是個別命名,String 是 CLR中的 string是C#中的
*****************************************************************************************************************
Array 和 ArrayList 的聯繫與區別
using System;
using System.Collections;
public class SamplesArrayList {
public static void Main() {
// Creates and initializes a new ArrayList.
ArrayList myAL = new ArrayList();
myAL.Add("Hello");
myAL.Add("World");
myAL.Add("!");
myAL.Add(3);
myAL.Add(8.5);
// Displays the properties and values of the ArrayList.
Console.WriteLine( "myAL" );
Console.WriteLine( " Count: {0}", myAL.Count );
Console.WriteLine( " Capacity: {0}", myAL.Capacity );
Console.Write( " Values:" );
PrintValues( myAL );
}
public static void PrintValues( IEnumerable myList ) {
foreach ( Object obj in myList )
Console.Write( " {0}", obj );
Console.WriteLine();
}
}
相同點:
- both of them are saved in the heap
- both of them have index, easier for locate
- both of them are implemented IEnumerable interface
不同點:
- different namespace: array is from system ---- arraylist is from system.collections
- Array need instantiation when declare it, ArrayList doesn't need instantiation in advance(Array需要在聲明的時候進行實例化,而ArrayList不需要)
- Array should given fixed length, but ArrayList can add more and more(Array必須是固定的長度 ArrayList可以隨意添加)
- Array可以是多維的 ArrayList只能是一維的(dimension)
- 一個Array只能存儲一種類型的值, 而ArrayList可以存儲不同類型的值
(可以簡單理解爲,ArrayList與Array的關係 相似於 StringBuilder與String的關係)
Array一旦建立object則無法進行修改,只能建立新的對象,這樣會非常浪費資源 -- ArrayList可以解決這個問題
ArrayList 可以通過 .toArray()的內置方法生成Array
****************************************************************************************************************
Static類與static方法
靜態類與靜態方法是爲了方便程序員編程,以爲其可以不用實例化就直接調用其中的方法
namespace CSharp_Console
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine(staticlass.GetCompanyName());
}
}
static class staticlass
{
public static string GetCompanyName() { return "CompanyName"; }
}
}
http://developer.51cto.com/art/200908/147748.htm
*****************************************************************************************************************
ASP.NET Page Tags
<% %> An embedded code block is server code that executes during the page's render phase. The code in the block can execute programming statements and call functions in the current page class. http://msdn2.microsoft.com/en-gb/library/ms178135(vs.80).aspx
<%= %> most useful for displaying single pieces of information. http://msdn2.microsoft.com/en-us/library/6dwsdcf5(VS.71).aspx
<%# %> Data Binding Expression Syntax. http://msdn2.microsoft.com/en-us/library/bda9bbfx.aspx
<%$ %> ASP.NET Expression. http://msdn2.microsoft.com/en-us/library/d5bd1tad.aspx
<%@ %> Directive Syntax. http://msdn2.microsoft.com/en-us/library/xz702w3e(VS.80).aspx
<%-- --%> Server-Side Comments. http://msdn2.microsoft.com/en-US/library/4acf8afk.aspx
<%: %> Like <%= %> But HtmlEncodes the output (new with Asp.Net 4). http://weblogs.asp.net/scottgu/archive/2010/04/06/new-lt-gt-syntax-for-html-encoding-output-in-asp-net-4-and-asp-net-mvc-2.aspx
*********************************************************************************************************************************
C# 中 覆蓋(Override) 和 重寫(Overload) 的區別
Override 是用於derived class 去覆蓋 base class 中的虛方法(virtual method), Overload 是在同一個類中 幾個方法同名,但是其參數(argument)不同
using System;
namespace test{
public class human
{
protected int eyes = 2; // the property must be static, if need using by derived class
protected int nose = 1;
public human(int eyes, int nose)
{
this.eyes = eyes;
this.nose = nose;
}
public virtual int FaceCounter()
{
return eyes + nose;
}
}
public class man : human
{
public int JB;
public man(int eyes, int nose,int JB) : base(eyes, nose)
{
this.JB = JB;
}
public override int FaceCounter()
{
return base.eyes * 2 + base.nose * 2;
}
}
class displayResult{
public static void Main()
{
human h = new human(2,1);
man m = new man(1,2,1);
Console.WriteLine(h.FaceCounter());
Console.WriteLine(m.FaceCounter());
Console.WriteLine(h.FaceCounter());
}
}
}
http://www.cnblogs.com/jiajiayuan/archive/2011/09/15/2177051.html
*****************************************************************************************************