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 公共语言运行时

 

 

转载于:https://www.cnblogs.com/ruanmou001/p/3753387.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值