asp.net常见面试题(一)

1、索引器

 class Player
{
private int[] arr = new int[];
public int this[int index]
{
get {
if (index < || index >= )
{
return ;
}
else
{
return arr[index];
}
}
set {
if (!(index < || index >= ))
{
arr[index] = value;
}
}
}
}
 class Program
{
static void Main(string[] args)
{
Player p = new Player();
p[] = ;
p[] = ;
Console.WriteLine(p[]);
Console.ReadKey();
}
}

2、应用程序域

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

demo1

 class Player
{
private static int i;
public void SetValue(int a)
{
i = a;
}
public int GetValue()
{
return i;
}
}
 class Program
{
static void Main(string[] args)
{
Player p1 = new Player();
p1.SetValue();
Player p2 = new Player();
p2.SetValue();
Console.WriteLine(p1.GetValue());
Console.WriteLine(p2.GetValue());
Console.ReadKey();
}
}

demo2

 public class Player:MarshalByRefObject
{
private static int i;
public void SetValue(int a)
{
i = a;
}
public int GetValue()
{
return i;
}
}
   private void Form1_Load(object sender, EventArgs e)
{
AppDomain appDomain1 = AppDomain.CreateDomain("domain1");
Player play1 = (Player)appDomain1.CreateInstanceFromAndUnwrap("WindowsFormsApplication1.exe", "WindowsFormsApplication1.Player");
play1.SetValue();
AppDomain appDomain2 = AppDomain.CreateDomain("domain2");
Player play2 = (Player)appDomain2.CreateInstanceFromAndUnwrap("WindowsFormsApplication1.exe", "WindowsFormsApplication1.Player");
play2.SetValue();
MessageBox.Show(play1.GetValue().ToString());
MessageBox.Show(play2.GetValue().ToString());
}

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

上一篇:CacheManager.NET


下一篇:一次tomcat数据乱码事件