.NET研发人员面试题(二)
1、当使用new BB()创建BB的实例时,产生什么输出?
public class AA { public AA() { PrintFields(); } public virtual void PrintFields() { } }
public class BB : AA { int x = 1; int y; public BB() { y = -1; } public override void PrintFields() { Console.WriteLine("x={0},y={1}", x, y); } }
输出:x=1,y=0.
2、下面分别输出什么
string st1 = "123" + "abc"; int _a = 123; string st2 = _a + "abc"; Console.WriteLine(st1 == st2); //true Console.WriteLine(st1.Equals(st2)); //true Console.WriteLine(System.Object.ReferenceEquals(st1, st2)); //false
3、下面语句共发生(3)次装箱,(1)次拆箱,请写出具体的拆装箱详情
int i = 0; System.Object obj = i; //装箱+1 Console.WriteLine(i + "," + (int)obj);//i + "," 装箱+1 ; (int)obj 拆箱+1 ; i + "," + (int)obj 装箱+1
4、写出一条sql语句:取出表A中第31到第40记录(SQLServer,以自动增长的ID作为主键,注意:ID可能不是连续的)。(至少写两种)
实际上考察的就是分页。
declare @pagecount integer --每页多少条记录 declare @pageindex integer --第几页 set @pagecount = 10 --初始化每页10条记录 set @pageindex = 3 --初始化当前的页数 --方式1:通过top关键字定位 select top (@pagecount) name from A where id not in (select top (@pagecount*@pageindex) id from A) --方式2:通过row_number函数定位 select name from (select ROW_NUMBER() over (order by id) as rownum,name from A) as D where rownum between @pageindex*@pagecount+1 and (@pageindex+1)*@pagecount