dotNET面试(一)

1.列举ASP.NET 页面之间传递值的几种方式。
1).使用QueryString, 如....?id=1; response. Redirect()....
2).使用Session变量
3).使用Server.Transfer

2.如果在一个B/S结构的系统中需要传递变量值,但是又不能使用Session、Cookie、Application,您有几种方法进行处理?
答 : QueryString、 this.Server.Transfer

3. 一列数的规则如下: 1、1、2、3、5、8、13、21、34...... 求第30位数是多少, 用递归算法实现。

 1 class Program
 2 {
 3     static void Main(string[] args)
 4     {
 5         Console.WriteLine(Foo(30));
 6         //输出 832040
 7         Console.ReadKey();
 8     }
 9     public static int Foo(int i)
10     {
11         if (i <= 0)
12             return 0;
13         else if (i > 0 && i <= 2)
14             return 1;
15         else return Foo(i - 1) + Foo(i - 2);
16     }
17 }
View Code

4.在下面的例子里,当使用new B()创建B的实例时,产生什么输出?

 1 class Program
 2 {
 3     static void Main(string[] args)
 4     {
 5         var test = new B();//x = 1, y = 0
 6         Console.ReadKey();
 7     }
 8 }
 9 class A
10 {
11     public A()
12     {
13         PrintFields();
14     }
15     public virtual void PrintFields() {}
16 }
17 class B:A
18 {
19     int x = 1;
20     int y;
21     public B()
22     {
23         y = -1;
24     }
25     public override void PrintFields()
26     {
27         Console.WriteLine("x = {0}, y = {1}", x, y);
28     }
29 }
View Code

5..net中读写数据库需要用到那些类?他们的作用?

SqlConnection/OleDbConnection:建立数据库的连接;
SqlCommand/OleDbCommand:执行数据库脚本。

6.ASP.NET与ASP相比,主要有哪些进步?
asp解释形,aspx编译型,性能提高,可以跟美工的工作分开进行,更有利于团队开发。

7.产生一个int数组,长度为100,并向其中随机插入1-100,并且不能重复。

 1 class Program
 2 {
 3     static void Main(string[] args)
 4     {
 5         int[] intArr = new int[100];
 6         ArrayList myList = new ArrayList();
 7         Random rnd = new Random();
 8         while (myList.Count < 100)
 9         {
10             int num = rnd.Next(1, 101);
11             if (!myList.Contains(num))
12                 myList.Add(num);
13         }
14         for (int i = 0; i < 100; i++ )
15         {
16             intArr[i] = (int)myList[i];
17         }
18         for (int i = 0; i < 100; i++ )
19         {
20             Console.Write(intArr[i] + "|");
21             if ((i + 1) % 10 == 0)
22             {
23                 Console.WriteLine();
24             }
25         }
26         Console.ReadKey();
27     }
28 }
View Code

8.DataReader与Dataset有什么区别?

一个是只能向前的只读游标,一个是内存中的表。

9.需要实现对一个字符串的处理,首先将该字符串首尾的空格去掉,如果字符串中间还有连续空格的话,仅保留一个空格,即允许字符串中间有多个空格,但连续的空格数不可超过一个

1 string inputStr = " xx xx ";
2 inputStr = Regex.Replace(inputStr.Trim(), @"s+", " ");

10.下面这段代码输出什么?为什么?

1 int i = 5; int j = 5;
2 if (Object.ReferenceEquals(i, j))
3 Console.WriteLine("Equal");
4 else Console.WriteLine("Not Equal");

不相等,因为比较的是对像。

11.什么是虚函数?什么是抽像函数?
虚函数(virtual):可由子类继承并重写的函数。抽像函数:规定其非虚子类必须实现的函数,必须被重写。

12.什么是ASP.net中的用户控件?
用户控件一般用在内容多为静态,或者少许会改变的情况下用的比较多,类似ASP中的include..但是功能要强大的多。

13.什么是code-Behind技术?
ASPX,RESX和CS三个后缀的文件,这个就是代码分离,实现了HTML代码和服务器代码分离,方便代码编写和整理。

14.当整数a赋值给一个object对像时,整数a将会被?装箱

15.public static const int A=1;这段代码有错误么?是什么?const不能用static修饰

16.下面的代码中有什么错误吗?abstract override 是不可以一起修饰

 1 class A
 2 {
 3 public virtual void F(){
 4 Console.WriteLine("A.F");
 5 }
 6 }
 7 abstract class B:A
 8 {
 9 public abstract override void F();
10 }

17.下面这段代码有错误么?

 1 switch (i){
 2 case()://case()条件不能为空
 3 CaseZero();
 4 break;
 5 case 1:
 6 CaseOne();
 7 break;
 8 case 2:
 9 default;//wrong,格式不正确
10 CaseTwo();
11 break;
12 }

18.写一个HTML页面,实现以下功能,左键点击页面时显示“您好”,右键点击时显示“禁止右键”。并在2分钟后自动关闭页面。

1 <script *** script>
2 setTimeout('window.close();', 3000);//1200
3 function show(){
4 if (window.event.button == 1){
5 alert("您好");
6 } else if (window.event.button == 2){
7 alert("禁止右键");
8 }
9 }

19.<%# %> 和 <% %> 有什么区别?<%# %>表示绑定的数据源;<% %>是服务器端代码块。

20.重载与覆盖的区别?
1、方法的覆盖是子类和父类之间的关系,是垂直关系;方法的重载是同一个类中方法之间的关系,是水平关系;
2、覆盖只能由一个方法,或只能由一对方法产生关系,方法的重载是多个方法之间的关系;
3、覆盖要求参数列表相同;重载要求参数列表不同;
4、覆盖关系中,调用那个方法体,是根据对象的类型(对像对应存储空间类型)来决定;重载关系,是根据调用时的实参表与形参表来选择方法体的。

21.分析以下代码:

 1 public static void test(string ConnectString)
 2 {
 3 System.Data.OleDb.OleDbConnection conn = new System.Data.OleDb.OleDbConnection();
 4 conn.ConnectString = ConnectString;
 5 try {
 6 conn.Open();
 7 ...
 8 } catch (Exception Ex){
 9 MessageBox.Show(Ex.ToString());
10 } finally {
11 if (!conn.State.Equals(ConnectionState.Closed))
12 conn.Close();
13 }
14 }

以上代码可以正确使用连接池吗?如果传入的connectionString是一模一样的话,可以正确使用连接池。不过一模一样的意思是,连字符的空格数,顺序完全一致。

22.下面的例子中

 1 class Program
 2 {
 3     static void Main(string[] args)
 4     {
 5         Console.WriteLine("X = {0}, Y = {1}", A.X, B.Y);//X = 2, Y = 1
 6         Console.ReadKey();
 7     }
 8 }
 9 class A
10 {
11     public static int X;
12     static A()
13     {
14         X = B.Y + 1;
15     }
16 }
17 class B
18 {
19     public static int Y = A.X + 1;
20     static B() { }
21 }
View Code
原文地址:https://www.cnblogs.com/hendrix/p/10712615.html