文档详情

c#常见面试题及答案.doc

发布:2017-08-16约1.61万字共19页下载文档
文本预览下载声明
2 .列举ASP.NET 页面之间传递值的几种方式。? 答. 1).使用QueryString, 如?id=1; response. Redirect()? ????????????????? 2).使用Session变量? ????????????????? 3).使用Server.Transfer 3. 一列数的规则如下: 1、1、2、3、5、8、13、21、34 求第30位数是多少, 用递归算法实现。 答:public class MainClass? ????????????????? {? ????????????????? public static void Main()? ????????????????? {? ????????????????? Console.WriteLine(Foo(30));? ????????????????? }? ????????????????? public static int Foo(int i)? ????????????????? {? ????????????????? if (i = 0)? ????????????????? return 0;? ????????????????? else if(i 0 i = 2)? ????????????????? return 1;? ????????????????? else return Foo(i -1) + Foo(i - 2);? ????????????????? }? ????????????????? } 4.C#中的委托是什么?事件是不是一种委托? 答 : 委托可以把一个方法作为参数代入另一个方法。 ????????委托可以理解为指向一个函数的引用。 ????????是,是一种特殊的委托 5.override与重载的区别 答 :?override 与重载的区别。重载是方法的名称相同。参数或参数类型不同,进行多次重载以适应不同的需要 ????????override 是进行基类中函数的重写。为了适应需要。 6.如果在一个B/S结构的系统中需要传递变量值,但是又不能使用Session、Cookie、Application,您有几种方法进行处理? 答 :?QueryString、?this.Server.Transfer,服务端cach,数据库 7.请编程遍历页面上所有TextBox控件并给它赋值为string.Empty? 答: foreach (Control control in this.Controls) { if (control is TextBox) { TextBox tb = (TextBox)control ;? tb.Text = String.Empty ; } } 8.请编程实现一个冒泡排序算法? 答: int [] array = new int [*] ; int temp = 0 ; for (int i = 0 ; i array.Length - 1 ; i++) { for (int j = i + 1 ; j array.Length ; j++) { if (array[j] array[i]) { temp = array[i] ; array[i] = array[j] ; array[j] = temp ; } } } 9.描述一下C#中索引器的实现过程,是否只能根据数字进行索引? 答:可以用任意类型。 10.求以下表达式的值,写出您想到的一种或几种实现方法: 1-2+3-4+……+m 答: 法一: int sum=0; bool flag=true; for(int i=1;i=m;i++) { ?? if(flag) ????? sum+=i; ?? else ????? sum-=i; ?? flag=!flag; } return sum; 法二: if((m%2)0) ?? return m/2; else ?? return -m/2; 12.在下面的例子里 using System; class A { public A() { PrintFields(); } public virtual void PrintFields(){} } class B:A { int x=1; int y; public B() { y=-1; } public override void PrintFields() { Console.WriteLine(x={0},y={1},x,y); } 当使用new B()创建B的实例时,产生什么输出? 答:X=1,Y=0 13.什么叫应用程序域? 答:。Net的运行环境,CLR将程序分成一个或多个逻
显示全部
相似文档