C#/ASP.NET/Javascript/SQL面试题

以下题目为真实的面试题目,答案中部分由网络搜索转载

----------------C#

1.C#如何显示pdf[有项目经验才知道]

一:使用Adobe reader提供的COM组件
1.添加引用
工具箱---右键---选择项--COM组件--Adobe PDF Reader
2.使用方法
 OpenFileDialog openFile=new OpenFileDialog();
 open..Filter = "PDF文件|*.pdf";
 openFile.ShowDialog();
 axAcroPDF1.src = openFile.FileName;
 //axAcroPDF1.LoadFile(of.FileName);   //使用方法二
二:不使用Adobe reader提供的COM组件
http://www.codeproject.com/KB/silverlight/BlendPDFwithSilverlight.aspx
http://www.codeproject.com/KB/applications/PDFViewerControl.aspx
或者其它开源方案

 

2.如下三个函数之间有什么不同[基础]

1 void test(string s)                test(ss)
2 void test(ref string s)            test(ref ss) 
3 void test(out string s)            test(out ss)

答案:

test(string s)  调用前传入的参数s必须初始化(包括null),如果test函数内部修改了s的值,传入的参数不会改变
test(ref string s) 调用前传入的参数s必须初始化(包括null),如果test函数内部修改了s的值,传入的参数也会改变
test(out string s) 调用前传入的参数s不需要初始化,如果test函数内部修改了s的值,传入的参数也会改变 

 

3.运行时异常和普通异常异同

普通异常:可捕捉的,可恢复异常,比如IO异常
运行时异常:不可捕捉,由系统进行处理的,无法恢复的错误
http://www.cnblogs.com/air5/archive/2011/11/07/2239399.html

4.请描述链式委托是什么

即 委托链,委托内部通过链表的方式将注册的方法进行保存,然后依次调用

5.C#实现了那几种可访问性级别

1 public               访问不受限制。
2 protected            访问仅限于包含类或从包含类派生的类型。
3 internal             访问仅限于当前程序集。
4 protected internal   访问仅限于从包含类派生的当前程序集或类型。
5 private              访问仅限于包含类型。

6.如何设置线程池并发线程的最大最小数量[这个题目脑残,除非记得很清楚,不然即使用过也很容易忘记]

1 System.Threading.ThreadPool.SetMaxThreads(50, 2000);
2 System.Threading.ThreadPool.SetMinThreads(50, 2000);

7.同步块和同步快索引的机制[线程]

http://www.cnblogs.com/yuyijq/archive/2009/03/13/1410071.html
http://genwoxuedotnet.blog.51cto.com/1852748/504107

8.根据线程安全的相关知识,分析以下代码,当调用test方法时i>10时是否会引起死锁?并简要说明理由。[线程]

 1 public void test(int i) 
 2  { 
 3     lock(this) 
 4    { 
 5       if (i > 10) 
 6      { 
 7           i--; 
 8           test(i); 
 9       } 
10     } 
11  }

答案:根据网上的资料,大都回答如下:

1)不会发生死锁,(但有一点int是按值传递的,所以每次改变的都只是一个副本,因此不会出现死锁。但如果把int换做一个object,那么死锁会发生)

经过实际程序验证和这种说法的结果是一致的,但是也另外一种说法,参看2)
以下是测试程序:
 1 public class Printer
 2 {
 3     public  void test(int i) 
 4     { 
 5         lock(this) 
 6         { 
 7             if (i > 10) 
 8             { 
 9             
10                 i--; 
11                 test(i); 
12                 Console.WriteLine(i);
13             } 
14         } 
15     }
16     public  void test(object aa) 
17     {
18         int i=20;
19             lock(this) 
20             { 
21                 if  (i > 10)
22                 { 
23                     i--; 
24                     Console.WriteLine("{0}\t{1}",i,aa);//去掉此句会产生异常StackOverflowException
25                     test(aa);                 
26                 } 
27             }     
28     }
29 }
30 
31 //调用
32     public static void Main()
33     {
34         Printer p = new Printer();
35         p.test(25);//不死锁
36 
37         try{
38             p.test("aaaaa");
39         }
40         catch( Exception  e)
41         {
42             Console.WriteLine(e);
43         }
44     }

2)《CLR via C#》第二版(中文版,清华大学出版社出版)的第530页中第7行找到了这样的描述:“同样需要引起注意的是线程可以递归拥有同步块”。即同一线程可以递归调用lock语句。

来源于:http://www.cnblogs.com/myshell/archive/2010/07/18/1780386.html

参考

http://www.cnblogs.com/csharp4/archive/2010/06/11/1756276.html
http://blog.csdn.net/xuexiaodong2009/article/details/6336696
http://msdn.microsoft.com/zh-cn/library/c5kehkcz.aspx

9.有三个线程ID分别是A、B、C,请有多线编程实现,在屏幕上循环打印10次ABCABC…[线程]

 1 public void PrintABC()
 2 {
 3     int count=0;
 4     string name=System.Threading.Thread.CurrentThread.Name;            
 5     while (count<10)
 6     {                
 7         if (ppp=="c" && name=="a" || ppp=="a" && name=="b" || ppp=="b" && name=="c" )
 8         {
 9                 //System.Console.Write("{0}{1}",count,name);
10                 System.Console.Write("{0}",name);
11                 ppp=name;
12                 count++;
13         }                
14     }                
15 }
16 
17 
18 //调用
19 for    (char c='a';c<'d';c++)
20 {
21     Thread tt=new Thread(new ThreadStart(t.PrintABC));    
22     tt.Name=c.ToString();
23     tt.Start();
24 }
25         

 

10.假如有字符串“6sabcsssfsfs33” ,用最快速的方法去掉字符“ab3”,不能用内置字符串方法(indeOf,substring,replaceAll等)? 

[老实说不知道要考什么]

 最快的不知道,随便写一个

 1 public string RemoveAB3(string s,string rs)
 2 {        
 3     string tmp="";
 4     for(int i=0;i<s.Length;i++)
 5     {
 6         bool bExist=false;
 7         //here,use hashset for rs 
 8         for(int j=0;j<rs.Length;j++)
 9         {                
10             if (s[i]==rs[j])
11             {
12                 bExist=true;
13             }                
14         }
15         if (!bExist) tmp+=s[i];
16     }
17     return tmp;
18 }
19 //调用
20 string s="6sabcsssfsfs33";
21 string s1="ab3";
22 System.Console.WriteLine("{0}\n{1}",s,t.RemoveAB3(s,s1));

 

----------------ADO.NET

1.ADO.NET常用5个类的名称[一般用过的大概都知道,悲惨是如果一开始就是用orm的,就不一定知道了]

DataSet
Connection
Command
DataReader
DataAdapter

2.下面四个方法,哪些可以返回数据[同上]

ExecuteNonQuery :执行 Transact-SQL INSERT、DELETE、UPDATE 及 SET 语句等命令。
ExecuteScalar :从数据库中检索单个值(例如一个聚合值)。
ExecuteReader :执行返回行的命令。
还有一个忘记

----------------ASP.NET

1.Asp.Net部署有哪几种方法

方法1:---直接复制到IIS目录发布目录中(C:\Inetpub\wwwroot)
方法2:---使用Vs2008的IDE自带的发布功能, 进行发布操作.
方法3: ---使用虚拟目录发布网站.
http://www.cnblogs.com/mishchael/articles/1897131.html

2.简单描述<%# eval("xxx")   %>机制

 Eval最终是调用DataBinder.Eval方法,DataBinder.Eval是采用反射来获取数据的,进行数据绑定 
http://www.cnblogs.com/oec2003/archive/2009/01/14/1375868.html
http://www.cnblogs.com/mr_jinrui/archive/2010/07/06/1772129.html

3.写出Asp.net页面生命周期中的事件

参考http://msdn.microsoft.com/zh-cn/library/ms178472.aspx

----------------SQL

1.SQL行转列(具体题目忘记,以如下例子代替)[case when ,sum,group by]

表格数据:
name,paytype,money,datatime
小李    支付宝   20   2012-01-03 00:00:00.000
小陈    工行     40   2012-01-06 00:00:00.000
小赵    交行     60   2012-01-06 00:00:00.000
小陈    支付宝    80   2012-01-06 00:00:00.000
小赵    工行     100    2012-01-16 00:00:00.000
小张    中行     120    2012-01-16 00:00:00.000
小李    支付宝    140    2012-01-16 00:00:00.000

请按照如下格式显示(银行的顺序不限制),每一个人在各银行的消费总和

name,支付宝,工行,交行,中行
小陈   80   40   0    0
小李   160  0    0    0
小张   0    0    0    120
小赵   0    100  60   0

答案:主要使用case when、sum、和group by

测试表格和数据

 1 --------创建行转列测试表格
 2 create table PayPhoneMoney
 3 (
 4     id int identity(1,1),
 5     userName nvarchar(20),
 6     payType nvarchar(20),
 7     money decimal,
 8     payTime datetime,
 9     constraint pk_id primary key(id)
10 )
11 
12 go
13 
14 --------插入行转列测试数据
15 delete from PayPhoneMoney
16  insert into PayPhoneMoney values('小李','支付宝',20,'2012-01-03')
17  insert into PayPhoneMoney values('小陈','工行',40,'2012-01-06')
18  insert into PayPhoneMoney values('小赵','交行',60,'2012-01-06')
19  insert into PayPhoneMoney values('小陈','支付宝',80,'2012-01-06')
20  insert into PayPhoneMoney values('小赵','工行',100,'2012-01-16')
21  insert into PayPhoneMoney values('小张','中行',120,'2012-01-16')
22  insert into PayPhoneMoney values('小李','支付宝',140,'2012-01-16')
23 
24 --------显示所有测试行数据
25 select  * from PayPhoneMoney username

方法1:

1 --------如果行转列中的列式有限且已知的几个,可以使用它case when语句
2 select username ,
3 sum(case payType when '支付宝' then money else 0 end) as '支付宝',
4 sum(case payType when '工行' then money else 0 end) as '工行',
5 sum(case payType when '交行' then money else 0 end) as '交行',
6 sum(case payType when '中行' then money else 0 end) as '中行'
7 from PayPhoneMoney
8 group by username

方法2:

 1 --------如果行转列中的列,是动态的且未知个数,使用如下方式
 2 --------原理就是根据通过select Distinct产生获取动态列对应的行,然后通过这些行以case when语句产生对应的列
 3 declare @cmdText varchar(8000)
 4 set @cmdText='select userName, '
 5 select @cmdText=@cmdText+' sum(case payType when '''+payType+''' then money else 0 end) as '''+payType
 6  +''','+char(10) from (select Distinct payType from PayPhoneMoney) T
 7 print @cmdText--发现最后多一个逗号下面把逗号去掉
 8 set @cmdText=left(@cmdText,len(@cmdText)-2)--去掉逗号
 9 set @cmdText=@cmdText+' from PayPhoneMoney group by userName'
10 print @cmdText
11 exec(@cmdText)

 2.内连接、左连接、右连接、全连接、交叉连接[前三个常用]

概念不解释,请自行搜索

例子:

部门表:id,name
雇员表:id,name,salary,title,manager,dept_id

测试数据:

 1 create table department
 2 (
 3     id int identity(1,1),
 4     name nvarchar(30),
 5 )
 6 go
 7 
 8 create table employee
 9 (
10     id int identity(1,1),
11     name nvarchar(30) not null,
12     salary money,
13     title nvarchar(30),
14     manager int,
15     dept_id int,
16 
17 )
18 go
19 
20 insert into department values('人力资源');
21 insert into department values('开发中心');
22 insert into department values('总裁室');
23 
24 insert into employee values('赵六',19000,'项目经理',null,2);
25 insert into employee values('王五',17000,'项目组长',4,2);
26 insert into employee values('张三',16000,'程序员',3,2);
27 insert into employee values('李四',17000,'HR',4,1);
 1 --内连接:是最常用的链接,也叫等值链接 
 2 --不管限制条件在on中还是在where中,内连接都得到笛卡尔积中满足所有条件的记录。对于inner join, on和where的效果是一样的。 
 3 --1)当没有限制条件,此时为笛卡尔积: 
 4 select * from employee,department
 5 select * from employee inner join department on 1=1
 6 --2)此时如果加上where限制条件,则对上面笛卡尔积的每一条记录看它是否满足限制条件,如果满足,则它在结果集中。
 7 select * from employee emp,department dept where emp.dept_id=dept.id
 8 select * from employee emp inner join department dept  on emp.dept_id=dept.id
 9 select * from employee emp cross join department dept  where emp.dept_id=dept.id
10 --左连接(left join): 
11 --1)当没加限制条件时,得到笛卡尔积,同内连接没加限制条件一样 [
12 select * from employee left join department on 1=1
13 --当添加特定条件时: 
14 select * from department
15 select * from employee
16 select * from employee emp left join department dept on emp.dept_id=dept.id
17 --右连接(right join): 
18 select * from employee emp right join department dept on emp.dept_id=dept.id
19 --全连接:
20 --会从左表 (employee) 和右表 (department) 那里返回所有的行。如果 "employee" 中的行在表 "department" 中没有匹配,或者如果 "department" 中的行在表 "employee" 中没有匹配,这些行同样会列出 
21 select * from employee emp full join department dept on 1=1

3.Union

合并两个数据表格,要求两个表列数相同,且对应列的类型是相似的

4.数据库有几种锁[]

独占锁
共享锁
更新锁
...

5.数据库分页[常用,但是一般都是调用写好的存储过程]

方法很多,请自行搜索,这里写一个简单的,但是效率不高的

1 select top @PageSize * from tb where id not in
2 (
3     select top (@PageIndex-1)*@PageSize id from tb order by id asc
4 )order by id asc;

 6.怎么防止sql注入

使用参数化查询方式(禁止拼凑字符串)

7.索引[提高效率的好方法]

好多个,请自行搜索

8.数据库优化

加索引 ,分布式数据库,横向切割表等等

9.如下两表

--订单
create table  [Order]
(
     
    OrderID int identity(1,1),
    CreateTime datetime,
)
--订单行
create table  OrderLine
(
     
    OrderLineID int identity(1,1),
    money decimal,
    Price decimal,
    count int,
    OrderID int,       -->Order.OrderID
)

1)请写出当天所有Order的OrderLine

select *   from OrderLine where orderid in (select orderid from [Order] where CreateTime between  '2010-12-11 00:00:00' and  '2010-12-11 23:59:59')
--or
select OrderLine.*   from OrderLine  right join [Order] on OrderLine.orderid=[Order].orderid where [Order].CreateTime between  '2010-12-11 00:00:00' and  '2010-12-11 23:59:59'

2)请列出每一笔总金额超过200的Order[考察对having和sum的运用]

select * from [Order] where orderid in (select orderid   from OrderLine group by orderid having sum(money*count) >200)
--or
select [Order].*   from [Order] left join (select orderid   from OrderLine group by orderid having sum(money*count) >200) b on b.orderid=[Order].orderid

3)忘记了

 10.请说出Cast和Convert的区别

http://hi.baidu.com/s_s_o_o/item/843c6d0c4e5d8d2ea1312deb

 

----------------Javascript
1.javascript/jquery实现字符串判断函数,长度在5-15之间,首字符必须是字母,其它字符可以是字母数字和下划线

[考察对正则表达式的运用]

1 function test(str)
2 {
3     var aa=/^[a-zA-Z]{1,1}[a-zA-Z0-9_]*$/gi;
4     return (str.length>=5 && str.length<=15)  && aa.test(str) ;
5 }
6 //调用    
7 var s="q1q_sdsdddddddd";
8 alert(test(s));

2.Ajax的工作原理

http://blog.csdn.net/yakihappy/article/details/3976960

3.Ajax的中文或者英文全称[莫名其妙的题目]

Asynchronous JavaScript and XML(非同步的JavaScript与XML)

----------------CSS

1.如何使容器(假设为DIV)水平和垂直同时居中

 1 .mainbar {
 2     /*必须设定高度和宽度*/
 3     width:500px;
 4      height:400px;
 5      /*设定绝对定位*/
 6     position: absolute; 
 7     /*将其左上顶点的位置放置于父容器的正中间*/
 8     top: 50%;
 9     left:50%;
10     /*向上平移自身高度的一半,向左移动自身宽度的一半*/
11     margin-top: -200px;
12     margin-left:-250px;
13  
14     background:green;
15 }
1 <div class="mainbar"></div>

 注意要点:

1)高度和宽度必须指定值
2)使用绝对定位
3)top和left必须设定为50%
4)margin-top和margin-left必须设定为自身高度和宽度的一半,且都为负值

2.三列div结构的实现方法

 1 //CSS
 2 <style type="text/css">
 3 * {
 4     margin:0;
 5     padding:0
 6 }
 7 .l-sidebar {
 8     width:200px;//必须设置
 9     height:500px;
10     position:absolute;//必须固定
11     top:0;
12     left:0;
13     background:blue;
14 }
15 .mainbar {
16     margin-left:200px;//左边容器宽度
17     margin-right:300px;//右边容器宽度
18     height:500px;
19     background:green;
20 }
21 .r-sidebar {
22     width:300px;//必须设定
23     height:500px;
24     position:absolute;//必须固定
25     top:0px;
26     right:0px;
27     background:blue;
28 }
29 </style>
1 //HTML
2 <div class="l-sidebar"></div>
3 <div class="mainbar"></div>
4 <div class="r-sidebar"></div>
简言之:左右容器固定位置,且都设定宽度,中间容器margin左右容器的宽度

还有其它方式,请自行搜索

3)左右两列div实现

 1 <style type="text/css">
 2 * {
 3     margin:0;
 4     padding:0
 5 }
 6 .l-sidebar {
 7     width:200px;
 8     height:500px;
 9     position:absolute;
10     top:0;
11     left:0;
12     background:blue;
13 }
14 .mainbar {
15     margin-left:200px;//此宽度就是左边容器宽度
16     
17     height:500px;
18     background:green;
19 }
20 
21 </style>
1 <div class="l-sidebar"></div>
2 <div class="mainbar"></div>

 

----------------XML

1.

 1 <?xml version="1.0" encoding="UTF-8" ?> 
 2 
 3 <?xml-stylesheet type="text/xsl" href="./employee.xsl"?>
 4 
 5 <root>
 6     <manager id="1001"/>
 7     <emplyee id="1001" >
 8         <name>韦小宝</name>
 9         <age>32</age>
10         <sex>male</sex>
11     </emplyee>
12     <emplyee id="1002" >
13         <name>张夏宏</name>
14         <age>26</age>
15         <sex>male</sex>
16     </emplyee>
17     <emplyee id="1003" >
18         <name>刘德华</name>
19         <age>27</age>
20         <sex>male</sex>
21     </emplyee>
22     <emplyee id="1004" >
23         <name>翁虹</name>
24         <age>25</age>
25         <sex>female</sex>
26     </emplyee>
27     <emplyee id="1005" >
28         <name>车晓</name>
29         <age>35</age>
30         <sex>female</sex>
31     </emplyee>
32 </root>

1)请用xpath表示出唯一的经理的名字

1 <xsl:value-of select="/root/emplyee[@id=/root/manager[1]/@id]/name/text()"/>
2 //or
3 <xsl:value-of select="/root/emplyee[@id='1001']/name/text()"/>

2)统计年龄在26岁以上员工的数量

1 <xsl:value-of select="count(/root/emplyee[age>26])"/>

3)显示所有女性员工名称

<xsl:for-each select="/root/emplyee[sex/text()='female']">
    <xsl:value-of select="./name/text()"/>
</xsl:for-each>

4)剩下的几个忘记了 

 

----------------算法题----[这种题目适合刚毕业的,老鸟们一般都不太记得]

1)用非递归和递归算法分别实现 斐波拉契序列:1,1,2,3,5,8,13

 1 public class Fibonacci 
 2 {
 3     //非递归
 4     public uint Calc(uint n)
 5     {
 6         uint nCur,nF,nL;
 7         nCur=nF=nL=1;
 8         if (n==1 ||n==2)
 9         {
10             return nCur;
11         }        
12         for(uint i=3;i<=n;i++)
13         {
14             nCur=nF+nL;
15             nF=nL;
16             nL=nCur;
17         }
18         return nCur;
19     }
20     //递归
21     public uint Calc1(uint n)
22     {
23         return (n==1 ||n==2)?1:Calc1(n-1)+Calc1(n-2);
24     }
25 }

2.已知0!=1,1!=1,2!=2*1!,3!=3*2!........n!=n*(n-1)!

请给定x,计算下面序列,1!,3!,5!.......(2x+1)!

 

----------------其它 

1.一个大矩形内部剪掉一个小矩形,大矩形完全包含剪掉的掉矩形,请在大矩形中画一条直线,将大矩形剩余部分分成面积相等的区域

 

 

转载于:https://www.cnblogs.com/simfe/archive/2012/10/29/2744987.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值