asp.net常见面试题(一)

1、索引器

 1 class Player
 2     {
 3         private int[] arr = new int[100];
 4         public int this[int index]
 5         {
 6             get {
 7                 if (index < 10 || index >= 10)
 8                 {
 9                     return 0;
10                 }
11                 else
12                 {
13                     return arr[index];
14                 }
15             }
16             set {
17                 if (!(index < 0 || index >= 100))
18                 {
19                     arr[index] = value;
20                 }
21             }
22         }
23     }
View Code
 1 class Program
 2     {
 3         static void Main(string[] args)
 4         {
 5             Player p = new Player();
 6             p[0] = 100;
 7             p[1] = 101;
 8             Console.WriteLine(p[0]);
 9             Console.ReadKey();
10         }
11     }
View Code

2、应用程序域

把一个程序进程分为各个独立的小进程,各个小进程中相互隔离,互不影响。

demo1

 1 class Player
 2     {
 3         private static int i;
 4         public void SetValue(int a)
 5         {
 6             i = a;
 7         }
 8         public int GetValue()
 9         {
10             return i;
11         }
12     }
View Code
 1 class Program
 2     {
 3         static void Main(string[] args)
 4         {
 5             Player p1 = new Player();
 6             p1.SetValue(5);
 7             Player p2 = new Player();
 8             p2.SetValue(10);
 9             Console.WriteLine(p1.GetValue());
10             Console.WriteLine(p2.GetValue());
11             Console.ReadKey();
12         }
13     }
View Code

demo2

 1 public class Player:MarshalByRefObject
 2     {
 3         private static int i;
 4         public void SetValue(int a)
 5         {
 6             i = a;
 7         }
 8         public int GetValue()
 9         {
10             return i;
11         }
12     }
View Code
 1   private void Form1_Load(object sender, EventArgs e)
 2         {
 3             AppDomain appDomain1 = AppDomain.CreateDomain("domain1");
 4             Player play1 = (Player)appDomain1.CreateInstanceFromAndUnwrap("WindowsFormsApplication1.exe", "WindowsFormsApplication1.Player");
 5             play1.SetValue(5);
 6             AppDomain appDomain2 = AppDomain.CreateDomain("domain2");
 7             Player play2 = (Player)appDomain2.CreateInstanceFromAndUnwrap("WindowsFormsApplication1.exe", "WindowsFormsApplication1.Player");
 8             play2.SetValue(100);
 9             MessageBox.Show(play1.GetValue().ToString());
10             MessageBox.Show(play2.GetValue().ToString()); 
11         }
View Code

3、CTS、CLS、CLR区别

cts:Comment Type System 通用系统类型,int32、int16--->int,String----->string,Boolean---->bool 不同语言变量类型不同,最后在.net上转换后都是同一种形式。

cls:Comment Language Specification 通用语言规范,不同语言语法不同,最后在.net上转换后都是同一种形式。

clr:Comment Language Runtime 公共语言运行时

 

 

asp.net常见面试题(一),古老的榕树,5-wow.com

郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。