ASP.NET Prepared for interview(3)

来源:互联网 发布:linux x86_64 编辑:程序博客网 时间:2024/06/06 09:53

.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 classhttp://msdn2.microsoft.com/en-gb/library/ms178135(vs.80).aspx

<%= %> most useful for displaying single pieces of informationhttp://msdn2.microsoft.com/en-us/library/6dwsdcf5(VS.71).aspx

<%# %> Data Binding Expression Syntaxhttp://msdn2.microsoft.com/en-us/library/bda9bbfx.aspx

<%$ %> ASP.NET Expressionhttp://msdn2.microsoft.com/en-us/library/d5bd1tad.aspx

<%@ %> Directive Syntaxhttp://msdn2.microsoft.com/en-us/library/xz702w3e(VS.80).aspx

<%-- --%> Server-Side Commentshttp://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

*****************************************************************************************************