悦山水 發表於 2019-11-29 17:34:00

ASP.NET(C#) 面试总结面试题大全

<p><span style="font-size: 15px"><strong><span style="background-color: rgba(255, 204, 0, 1)">一、对于 Web 性能优化,您有哪些了解和经验吗?</span></strong></span><br>出现指数:五颗星<br>主要考点:这道题是博主在博客园的新闻里面看到的,回想之前几年的面试经历,发现此题出现概率还是比较高的。因为它的考面灰常广,可以让面试官很快了解你的技术涉及面以及这些技术面的深度。<br>参考答案:这个问题可以分前端和后端来说。<br>1、前端优化<br>(1)减少 HTTP 请求的次数。我们知道每次发送http请求,建立连接和等待相应会花去相当一部分时间,所以在发送http请求的时候,尽量减少请求的次数,一次请求能取出的数据就不要分多次发送。<br>(2)启用浏览器缓存,当确定请求的数据不会发生变化时,能够直接读浏览器缓存的就不要向服务端发送请求。比如我们ajax里面有一个参数能够设置请求的时候是否启用缓存,这种情况下就需要我们在发送请求的时候做好相应的缓存处理。<br>(3)css文件放 在&lt;head&gt;里面,js文件尽量放在页面的底部。因为请求js文件是很花费时间,如果放在&lt;head&gt;里面,就会导致页面的 DOM树呈现需要等待js文件加载完成。这也就是为什么很多网站的源码里面看到引用的文件放在最后的原因。<br>(4)使用压缩的css和js文件。这个不用多说,网络流量小。<br>(5)如果条件允许,尽量使用CDN的方式引用文件,这样就能减少网络流量。比如我们常用的网站http://www.bootcdn.cn/。<br>(6)在写js和css的语法时,尽量避免重复的css,尽量减少js里面循环的次数,诸如此类。<br>2、后端优化:<br>(1)程序的优化:这是一个很大的话题,我这里就选几个常见的。比如减少代码的层级结构、避免循环嵌套、避免循环CURD数据库、优化算法等等。<br>(2)数据库的优化:(由于数据库优化不是本题重点,所以可选几个主要的来说)比如启用数据库缓存、常用的字段建索引、尽量避免大事务操作、避免select * 的写法、尽量不用in和not in 这种耗性能的用法等等。<br>(3)服务器优化:(这个可作为可选项)负载均衡、Web服务器和数据库分离、UI和Service分离等等。</p>
<p><br><span style="background-color: rgba(255, 204, 0, 1); font-size: 15px"><strong>二、MVC路由理解?(屡见不鲜)</strong></span><br>出现指数:五颗星<br>主要考点:此题主要考点是MVC路由的理解。<br>参考答案:<br>1、首先我们要理解MVC中路由的作用:url Routing的作用是将浏览器的URL请求映射到特定的MVC控制器动作。<br>2、当我们访问http://localhost:8080/Home/Index 这个地址的时候,请求首先被UrlRoutingModule截获,截获请求后,从Routes中得到与当前请求URL相符合的RouteData对象, 将RouteData对象和当前URL封装成一个RequestContext对象,然后从Requestcontext封装的RouteData中得到 Controller名字,根据Controller的名字,通过反射创建控制器对象,这个时候控制器才真正被激活,最后去执行控制器里面对应的 action。</p>
<p><span style="background-color: rgba(255, 204, 0, 1); font-size: 15px"><strong>三、谈谈你觉得做的不错系统,大概介绍下用到了哪些技术?</strong></span><br>出现指数:五颗星<br>主要考点:这是一道非常开放的面试题。博主遇到过好几家公司的面试官都问道了这个,博主觉得他们是想通过这个问题快速了解面试者的技术水平。此题只要结合你最近项目用到的技术谈谈就好了。<br>参考答案:<br>就拿我之前做过的一个项目为例来简单说明一下吧。项目分为客户端和服务端,客户端分 为BS客户端和CS客户端,BS客户端采用MVC 5.0的框架,CS客户端是Winform项目,服务端使用WebApi统一提供服务接口,考虑以后可能还要扩展手机端,所以服务接口的参数和返回值使用 通用的Json格式来传递数据。<br>1、服务端采用的面向接口编程,我们在软件架构的过程中,层和层之间通过接口依赖, 下层不是直接给上层提供实现,而是提供接口,具体的实现以依赖注入的方式在运行的时候动态注入进去。MEF就是实现依赖注入的一种组件。它的使用使得UI 层不直接依赖于BLL层,而是依赖于中间的一个IBLL层,在程序运行的时候,通过MEF动态将BLL里面的实现注入到UI层里面去,这样做的好处是减少 了层与层之间的耦合。服务端的异常里面、权限验证、日志记录等通用功能使用了AOP拦截的机制统一管理,项目中使用的是Postsharp这个组件,很好 地将通用需求功能从不相关的类当中分离出来,提高了代码的可维护性。<br>2、BS的客户端采用的jquery+bootstrap 的方式,所有页面采用流式布局,能更好适应各种不同的终端设备(PC、手机)。项目中使用了各种功能强大的bootstrap组件,能适应各种复杂的业务需求。</p>
<p><span style="font-size: 15px; background-color: rgba(255, 204, 0, 1)"><strong>四、Js继承实现。</strong></span><br>出现指数:五颗星<br>主要考点:这道题考验面试者对js理解的深度。根据博主的经历,这种题一般在笔试出现的几率较大,为什么把它放在这里,因为它确实太常见了。其实js实现继承的方式很多,我们只要写好其中一种就好了。<br>参考答案:原型链继承</p>
<div class="cnblogs_code">
<pre><span style="color: rgba(0, 128, 128, 1)"> 1</span> <span style="color: rgba(0, 128, 0, 1)">//</span><span style="color: rgba(0, 128, 0, 1)">1.定义Persiong函数</span>
<span style="color: rgba(0, 128, 128, 1)"> 2</span>             <span style="color: rgba(0, 0, 255, 1)">function</span><span style="color: rgba(0, 0, 0, 1)"> Person(name, age) {
</span><span style="color: rgba(0, 128, 128, 1)"> 3</span>               <span style="color: rgba(0, 0, 255, 1)">this</span>.name =<span style="color: rgba(0, 0, 0, 1)"> name;
</span><span style="color: rgba(0, 128, 128, 1)"> 4</span>               <span style="color: rgba(0, 0, 255, 1)">this</span>.age =<span style="color: rgba(0, 0, 0, 1)"> age;
</span><span style="color: rgba(0, 128, 128, 1)"> 5</span> <span style="color: rgba(0, 0, 0, 1)">            }
</span><span style="color: rgba(0, 128, 128, 1)"> 6</span>             <span style="color: rgba(0, 128, 0, 1)">//</span><span style="color: rgba(0, 128, 0, 1)">2.通过原型链给Person添加一个方法</span>
<span style="color: rgba(0, 128, 128, 1)"> 7</span>             Person.prototype.getInfo = <span style="color: rgba(0, 0, 255, 1)">function</span><span style="color: rgba(0, 0, 0, 1)"> () {
</span><span style="color: rgba(0, 128, 128, 1)"> 8</span>               console.log(<span style="color: rgba(0, 0, 255, 1)">this</span>.name + " is " + <span style="color: rgba(0, 0, 255, 1)">this</span>.age + " years old!"<span style="color: rgba(0, 0, 0, 1)">);
</span><span style="color: rgba(0, 128, 128, 1)"> 9</span> <span style="color: rgba(0, 0, 0, 1)">            }
</span><span style="color: rgba(0, 128, 128, 1)">10</span>             <span style="color: rgba(0, 0, 255, 1)">function</span><span style="color: rgba(0, 0, 0, 1)"> Teacher(staffId) {
</span><span style="color: rgba(0, 128, 128, 1)">11</span>               <span style="color: rgba(0, 0, 255, 1)">this</span>.staffId =<span style="color: rgba(0, 0, 0, 1)"> staffId;
</span><span style="color: rgba(0, 128, 128, 1)">12</span> <span style="color: rgba(0, 0, 0, 1)">            }
</span><span style="color: rgba(0, 128, 128, 1)">13</span>             <span style="color: rgba(0, 128, 0, 1)">//</span><span style="color: rgba(0, 128, 0, 1)">3.通过prototype生命 Teacher继承Person</span>
<span style="color: rgba(0, 128, 128, 1)">14</span>             Teacher.prototype = <span style="color: rgba(0, 0, 255, 1)">new</span><span style="color: rgba(0, 0, 0, 1)"> Person();
</span><span style="color: rgba(0, 128, 128, 1)">15</span>             <span style="color: rgba(0, 128, 0, 1)">//</span><span style="color: rgba(0, 128, 0, 1)">4.实例Teacher函数</span>
<span style="color: rgba(0, 128, 128, 1)">16</span>             <span style="color: rgba(0, 0, 255, 1)">var</span> will = <span style="color: rgba(0, 0, 255, 1)">new</span> Teacher(1000<span style="color: rgba(0, 0, 0, 1)">);
</span><span style="color: rgba(0, 128, 128, 1)">17</span>             will.name= "Will"<span style="color: rgba(0, 0, 0, 1)">;
</span><span style="color: rgba(0, 128, 128, 1)">18</span>             will.age = 28<span style="color: rgba(0, 0, 0, 1)">;
</span><span style="color: rgba(0, 128, 128, 1)">19</span>             <span style="color: rgba(0, 128, 0, 1)">//</span><span style="color: rgba(0, 128, 0, 1)">5.调用父类函数</span>
<span style="color: rgba(0, 128, 128, 1)">20</span>             will.getInfo();</pre>
</div>
<p><br><span style="font-size: 15px"><strong><span style="background-color: rgba(255, 204, 0, 1)">五、谈谈你对设计模式的认识?结合你用得最多的一种设计模式说说它的使用。</span></strong></span><br>出现指数:五颗星<br>主要考点:不用多说,这题考的就是对设计模式的理解。一般为了简单可能会要求你写一个单例模式,注意最好是写一个完整点的,考虑线程安全的那种。然后会让你说说你在项目中什么情况下会用到这种模式<br>参考答案:<br>通用写法</p>
<div class="cnblogs_code">
<pre><span style="color: rgba(0, 128, 128, 1)"> 1</span>   <span style="color: rgba(0, 0, 255, 1)">public</span> <span style="color: rgba(0, 0, 255, 1)">class</span><span style="color: rgba(0, 0, 0, 1)"> Singleton
</span><span style="color: rgba(0, 128, 128, 1)"> 2</span> <span style="color: rgba(0, 0, 0, 1)">    {
</span><span style="color: rgba(0, 128, 128, 1)"> 3</span>         <span style="color: rgba(0, 128, 0, 1)">//</span><span style="color: rgba(0, 128, 0, 1)"> 定义一个静态变量来保存类的实例</span>
<span style="color: rgba(0, 128, 128, 1)"> 4</span>         <span style="color: rgba(0, 0, 255, 1)">private</span> <span style="color: rgba(0, 0, 255, 1)">static</span><span style="color: rgba(0, 0, 0, 1)"> Singleton uniqueInstance;
</span><span style="color: rgba(0, 128, 128, 1)"> 5</span>         <span style="color: rgba(0, 128, 0, 1)">//</span><span style="color: rgba(0, 128, 0, 1)"> 定义一个标识确保线程同步</span>
<span style="color: rgba(0, 128, 128, 1)"> 6</span>         <span style="color: rgba(0, 0, 255, 1)">private</span> <span style="color: rgba(0, 0, 255, 1)">static</span> <span style="color: rgba(0, 0, 255, 1)">readonly</span> <span style="color: rgba(0, 0, 255, 1)">object</span> locker = <span style="color: rgba(0, 0, 255, 1)">new</span> <span style="color: rgba(0, 0, 255, 1)">object</span><span style="color: rgba(0, 0, 0, 1)">();
</span><span style="color: rgba(0, 128, 128, 1)"> 7</span>         <span style="color: rgba(0, 128, 0, 1)">//</span><span style="color: rgba(0, 128, 0, 1)"> 定义私有构造函数,使外界不能创建该类实例</span>
<span style="color: rgba(0, 128, 128, 1)"> 8</span>         <span style="color: rgba(0, 0, 255, 1)">private</span><span style="color: rgba(0, 0, 0, 1)"> Singleton()
</span><span style="color: rgba(0, 128, 128, 1)"> 9</span> <span style="color: rgba(0, 0, 0, 1)">      {
</span><span style="color: rgba(0, 128, 128, 1)">10</span> <span style="color: rgba(0, 0, 0, 1)">      }
</span><span style="color: rgba(0, 128, 128, 1)">11</span>         <span style="color: rgba(128, 128, 128, 1)">///</span> <span style="color: rgba(128, 128, 128, 1)">&lt;summary&gt;</span>
<span style="color: rgba(0, 128, 128, 1)">12</span>         <span style="color: rgba(128, 128, 128, 1)">///</span><span style="color: rgba(0, 128, 0, 1)"> 定义公有方法提供一个全局访问点,同时你也可以定义公有属性来提供全局访问点
</span><span style="color: rgba(0, 128, 128, 1)">13</span>         <span style="color: rgba(128, 128, 128, 1)">///</span> <span style="color: rgba(128, 128, 128, 1)">&lt;/summary&gt;</span>
<span style="color: rgba(0, 128, 128, 1)">14</span>         <span style="color: rgba(128, 128, 128, 1)">///</span> <span style="color: rgba(128, 128, 128, 1)">&lt;returns&gt;&lt;/returns&gt;</span>
<span style="color: rgba(0, 128, 128, 1)">15</span>         <span style="color: rgba(0, 0, 255, 1)">public</span> <span style="color: rgba(0, 0, 255, 1)">static</span><span style="color: rgba(0, 0, 0, 1)"> Singleton GetInstance()
</span><span style="color: rgba(0, 128, 128, 1)">16</span>         {<span style="color: rgba(0, 128, 0, 1)">//</span><span style="color: rgba(0, 128, 0, 1)"> 双重锁定只需要一句判断就可以了</span>
<span style="color: rgba(0, 128, 128, 1)">17</span>             <span style="color: rgba(0, 0, 255, 1)">if</span> (uniqueInstance == <span style="color: rgba(0, 0, 255, 1)">null</span><span style="color: rgba(0, 0, 0, 1)">)
</span><span style="color: rgba(0, 128, 128, 1)">18</span> <span style="color: rgba(0, 0, 0, 1)">            {
</span><span style="color: rgba(0, 128, 128, 1)">19</span>               <span style="color: rgba(0, 0, 255, 1)">lock</span><span style="color: rgba(0, 0, 0, 1)"> (locker)
</span><span style="color: rgba(0, 128, 128, 1)">20</span> <span style="color: rgba(0, 0, 0, 1)">                {
</span><span style="color: rgba(0, 128, 128, 1)">21</span>                     <span style="color: rgba(0, 128, 0, 1)">//</span><span style="color: rgba(0, 128, 0, 1)"> 如果类的实例不存在则创建,否则直接返回</span>
<span style="color: rgba(0, 128, 128, 1)">22</span>                     <span style="color: rgba(0, 0, 255, 1)">if</span> (uniqueInstance == <span style="color: rgba(0, 0, 255, 1)">null</span><span style="color: rgba(0, 0, 0, 1)">)
</span><span style="color: rgba(0, 128, 128, 1)">23</span> <span style="color: rgba(0, 0, 0, 1)">                  {
</span><span style="color: rgba(0, 128, 128, 1)">24</span>                         uniqueInstance = <span style="color: rgba(0, 0, 255, 1)">new</span><span style="color: rgba(0, 0, 0, 1)"> Singleton();
</span><span style="color: rgba(0, 128, 128, 1)">25</span> <span style="color: rgba(0, 0, 0, 1)">                  }
</span><span style="color: rgba(0, 128, 128, 1)">26</span> <span style="color: rgba(0, 0, 0, 1)">                }
</span><span style="color: rgba(0, 128, 128, 1)">27</span> <span style="color: rgba(0, 0, 0, 1)">            }
</span><span style="color: rgba(0, 128, 128, 1)">28</span>             <span style="color: rgba(0, 0, 255, 1)">return</span><span style="color: rgba(0, 0, 0, 1)"> uniqueInstance;
</span><span style="color: rgba(0, 128, 128, 1)">29</span> <span style="color: rgba(0, 0, 0, 1)">      }
</span><span style="color: rgba(0, 128, 128, 1)">30</span>   }</pre>
</div>
<p>单例模式确保一个类只有一个实例,并提供一个全局访问点,它的使用场景比如任务管理 器整个系统中应该只有一个把,再比如操作文件的对象,同一时间我们只能有一个对象**作文件吧。最重要的,比如我们项目中用得非常多的功能→日志记录,在 一个线程中,记录日志的对象应该也只能有一个吧。单例模式的目的是为了保证程序的安全性和数据的唯一性。或者你也可以结合你使用的其他设计模式来说明。</p>
<p>&nbsp;</p>
<p><span style="font-size: 15px"><strong><span style="background-color: rgba(255, 204, 0, 1)">六、IIS的工作原理?</span></strong></span><br>出现指数:四颗星<br>主要考点:此题主要考的是.net framework和IIS是如何结合呈现页面的。这是一个有点复杂的过程,面试的时候不可能说得完整,那么我们就抓住几个关键点说说就可以。其实博主也不能完全理解这个过程,今天正好借这个机会温**下。<br>参考答案:<br>1、当客户端发送HTTP Request时,服务端的HTTP.sys(可以理解为IIS的一个监听组件) 拦截到这个请求;<br>2、HTTP.sys 联系 WAS 向配置存储中心请求配置信息。<br>3、然后将请求传入IIS的应用程序池。<br>4、检查请求的后缀,启动aspnet_isapi.dll这个dll,这个dll是.net framework里面的,也就是说到这一步,请求进入了.net framework的管辖范围。<br>5、这个时候如果是WebForm,开始执行复杂的页面生命周期(HttpRuntime→ProcessRequest→HttpContext→HttpHandler);如果是MVC,则启动mvc的路由机制,根据路由规则为URL来指定HttpHandler。<br>6、httpHandler处理请求后,请求结束,给出Response,客户端处理响应,整个过程结束。</p>
<p><br><span style="font-size: 15px"><strong><span style="background-color: rgba(255, 204, 0, 1)">七、Http协议</span></strong></span><br>出现指数:四颗星<br>主要考点:此题主要考对于web里面http协议的理解。<br>参考答案:<br>1、http协议是浏览器和服务器双方共同遵循的规范,是一种基于TCP/IP应用层协议。<br>2、http是一种典型的请求/响应协议。客户端发送请求,请求的内容以及参数存放到请求报文里面,服务端收到请求后,做出响应,返回响应的结果放到响应报文里面。通过F12可以查看请求报文和响应报文。<br>3、http协议是”无状态”的,当客户端向服务端发送一次http请求后,服务端收到请求然后返回给客户端相应的结果,服务器会立即断开连接并释放资源。在实际开发过程中,我们有时需要“保持”这种状态,所以衍生出了Session/Cookie这些技术。<br>4、http请求的方式主要有get/post。<br>5、http状态码最好记几个,博主有一次面试就被问到了。200(请求成功)、404(请求的资源不存在)、403(禁止访问)、5xx(服务端错误)</p>
<p><br><span style="font-size: 15px"><strong><span style="background-color: rgba(255, 204, 0, 1)">八、数据库优化经验(后端工程师非常常见)</span></strong></span><br>出现指数:四颗星<br>主要考点:此题考察后端工程师操作数据库的经验。说实话,数据库是博主的弱项,博主觉得对于这种考题,需要抓住几个常用并且关键的优化经验,如果说得不对,欢迎大家斧正。<br>参考答案:<br>1、数据库运维方面的优化:启用数据库缓存。对于一些比较常用的查询可以采用数据库缓存的机制,部署的时候需要注意设置好缓存依赖项,防止“过期”数据的产生。<br>2、数据库索引方面的优化:比如常用的字段建索引,联合查询考虑联合索引。(PS:如果你有基础,可以敞开谈谈聚集索引和非聚集索引的使用场景和区别)<br>3、数据库查询方面的优化:避免select * 的写法、尽量不用in和not in 这种耗性能的用法等等。<br>4、数据库算法方面的优化:尽量避免大事务操作、减少循环算法,对于大数据量的操作,避免使用游标的用法等等。</p>
<p><br><span style="font-size: 15px"><strong><span style="background-color: rgba(255, 204, 0, 1)">九、关于代码优化你怎么理解?你会考虑去代码重构吗?</span></strong></span><br>出现指数:四颗星<br>主要考点:此题考的是面试者对代码优化的理解,以及代码如何重构的相关知识。<br>参考答案:<br>1、对于代码优化,之前的公司每周会做代码审核,审核的主要作用就是保证代码的正确性和执行效率,比如减少代码的层级结构、避免循环嵌套、避免循环CURD数据库、尽量避免一次取出大量数据放在内存中(容易内存溢出)、优化算法等。<br>2、对于陈旧代码,可能很多地方有调用,并且开发和维护人员很有可能不是同一个人,所以重构时要格外小心,如果没有十足的把握,不要轻易重构。如果必须要重构,必须做好充分的单元测试和全局测试。</p>
<p><br><span style="font-size: 15px"><strong><span style="background-color: rgba(255, 204, 0, 1)">十、谈谈你的优点和缺点?</span></strong></span><br>出现指数:四颗星<br>主要考点:这道题让人有一种骂人的冲动,但是没办法,偏偏很多所谓的大公司会问这个。比如华为。这个问题见仁见智,答案可以自己组织。<br>参考答案:<br>优点:对于新的技术学**能力强,能很快适应新环境等等<br>缺点:对技术太过于执着等等</p>
<p><br><span style="font-size: 15px"><strong><span style="background-color: rgba(255, 204, 0, 1)">十一、关于服务器端 MVC 架构的技术实现,您是怎样理解的?这种架构方式有什么好处?您在项目中是如何应用这一架构的?</span></strong></span><br>出现指数:三颗星<br>主要考点:此题主要考的对于MVC这种框架的理解。<br>参考答案:MVC,顾名思义,Model、View、Controller。所有的 界面代码放在View里面,所有涉及和界面交互以及URL路由相关的逻辑都在Controller里面,Model提供数据模型。MVC的架构方式会让系 统的可维护性更高,使得每一部分更加专注自己的职责,并且MVC提供了强大的路由机制,方便了页面切换和界面交互。然后可以结合和WebForm的比较, 谈谈MVC如何解决复杂的控件树生成、如何避免了复杂的页面生命周期。</p>
<p><span style="font-size: 15px"><strong><span style="background-color: rgba(255, 204, 0, 1)">十二、网站优化:网站运行慢,如何定位问题?发现问题如何解决?</span></strong></span><br>出现指数:三颗星<br>主要考点:此题和问题一类似,考察Web的问题定位能力和优化方案。<br>参考答案:<br>浏览器F12→网络→查看http请求数以及每个请求的耗时,找到问题的根源,然后依次解决,解决方案可以参考问题一里面的Web优化方案。</p>
<p><br><span style="background-color: rgba(255, 204, 0, 1); font-size: 15px"><strong>十三、说说你最擅长的技术?并说说你是如何使用的?</strong></span><br>出现指数:三颗星<br>主要考点:这是一道非常开放的面试题。最初遇到这种问题,博主很想来一句:你妹,这叫什么问题!但确实有面试官问到。回头想想,其实此题考查你擅长的技术的涉及深度。其实博主觉得对于这个问题,可以结合你项目中用到的某一个技术来说就好了。<br>参考答案:<br>简单谈谈MEF在我们项目里面的使用吧。<br>在谈MEF之前,我们必须要先谈谈DIP、IOC、DI<br>依赖倒置原则(DIP):一种软件架构设计的原则(抽象概念)<br>控制反转(IoC):一种反转流、依赖和接口的方式(DIP的具体实现方式)。<br>依赖注入(DI):IoC的一种实现方式,用来反转依赖(IoC的具体实现方式)。<br>什么意思呢?也就是说,我们在软件架构的过程中,层和层之间通过接口依赖,下层不是 直接给上层提供实现,而是提供接口,具体的实现以依赖注入的方式在运行的时候动态注入进去。MEF就是实现依赖注入的一种组件。它的使用使得UI层不直接 依赖于BLL层,而是依赖于中间的一个IBLL层,在程序运行的时候,通过MEF动态将BLL里面的实现注入到UI层里面去,这样做的好处是减少了层与层 之间的耦合。这也正是面向接口编程方式的体现。</p>
<p><br><span style="font-size: 15px"><strong><span style="background-color: rgba(255, 204, 0, 1)">十四、自己写过JS组件吗?举例说明。</span></strong></span><br>出现指数:三颗星<br>主要考点:此题考的js组件封装和js闭包的一些用法。一般来说,还是笔试出现的几率较大。<br>参考答案:自定义html的select组件<br>&nbsp;</p>
<div class="cnblogs_code">
<pre><span style="color: rgba(0, 128, 128, 1)"> 1</span><span style="color: rgba(0, 128, 0, 1)">//</span><span style="color: rgba(0, 128, 0, 1)">combobox</span>
<span style="color: rgba(0, 128, 128, 1)"> 2</span>   (<span style="color: rgba(0, 0, 255, 1)">function</span><span style="color: rgba(0, 0, 0, 1)"> ($) {
</span><span style="color: rgba(0, 128, 128, 1)"> 3</span>         $.fn.combobox = <span style="color: rgba(0, 0, 255, 1)">function</span><span style="color: rgba(0, 0, 0, 1)"> (options, param) {
</span><span style="color: rgba(0, 128, 128, 1)"> 4</span>             <span style="color: rgba(0, 0, 255, 1)">if</span> (<span style="color: rgba(0, 0, 255, 1)">typeof</span> options == 'string'<span style="color: rgba(0, 0, 0, 1)">) {
</span><span style="color: rgba(0, 128, 128, 1)"> 5</span>               <span style="color: rgba(0, 0, 255, 1)">return</span> $.fn.combobox.methods(<span style="color: rgba(0, 0, 255, 1)">this</span><span style="color: rgba(0, 0, 0, 1)">, param);
</span><span style="color: rgba(0, 128, 128, 1)"> 6</span> <span style="color: rgba(0, 0, 0, 1)">            }
</span><span style="color: rgba(0, 128, 128, 1)"> 7</span>             options = .fn.combobox.defaults, options ||<span style="color: rgba(0, 0, 0, 1)"> {});
</span><span style="color: rgba(0, 128, 128, 1)"> 8</span>             <span style="color: rgba(0, 0, 255, 1)">var</span> target = $(<span style="color: rgba(0, 0, 255, 1)">this</span><span style="color: rgba(0, 0, 0, 1)">);
</span><span style="color: rgba(0, 128, 128, 1)"> 9</span>             target.attr('valuefield'<span style="color: rgba(0, 0, 0, 1)">, options.valueField);
</span><span style="color: rgba(0, 128, 128, 1)">10</span>             target.attr('textfield'<span style="color: rgba(0, 0, 0, 1)">, options.textField);
</span><span style="color: rgba(0, 128, 128, 1)">11</span> <span style="color: rgba(0, 0, 0, 1)">            target.empty();
</span><span style="color: rgba(0, 128, 128, 1)">12</span>             <span style="color: rgba(0, 0, 255, 1)">var</span> option = $('&lt;option&gt;&lt;/option&gt;'<span style="color: rgba(0, 0, 0, 1)">);
</span><span style="color: rgba(0, 128, 128, 1)">13</span>             option.attr('value', ''<span style="color: rgba(0, 0, 0, 1)">);
</span><span style="color: rgba(0, 128, 128, 1)">14</span> <span style="color: rgba(0, 0, 0, 1)">            option.text(options.placeholder);
</span><span style="color: rgba(0, 128, 128, 1)">15</span> <span style="color: rgba(0, 0, 0, 1)">            target.append(option);
</span><span style="color: rgba(0, 128, 128, 1)">16</span>             <span style="color: rgba(0, 0, 255, 1)">if</span><span style="color: rgba(0, 0, 0, 1)"> (options.data) {
</span><span style="color: rgba(0, 128, 128, 1)">17</span> <span style="color: rgba(0, 0, 0, 1)">                init(target, options.data);
</span><span style="color: rgba(0, 128, 128, 1)">18</span> <span style="color: rgba(0, 0, 0, 1)">            }
</span><span style="color: rgba(0, 128, 128, 1)">19</span>             <span style="color: rgba(0, 0, 255, 1)">else</span><span style="color: rgba(0, 0, 0, 1)"> {
</span><span style="color: rgba(0, 128, 128, 1)">20</span>               <span style="color: rgba(0, 128, 0, 1)">//</span><span style="color: rgba(0, 128, 0, 1)">var param = {};</span>
<span style="color: rgba(0, 128, 128, 1)">21</span> <span style="color: rgba(0, 0, 0, 1)">                options.onBeforeLoad.call(target, option.param);
</span><span style="color: rgba(0, 128, 128, 1)">22</span>               <span style="color: rgba(0, 0, 255, 1)">if</span> (!options.url) <span style="color: rgba(0, 0, 255, 1)">return</span><span style="color: rgba(0, 0, 0, 1)">;
</span><span style="color: rgba(0, 128, 128, 1)">23</span>               $.getJSON(options.url, option.param, <span style="color: rgba(0, 0, 255, 1)">function</span><span style="color: rgba(0, 0, 0, 1)"> (data) {
</span><span style="color: rgba(0, 128, 128, 1)">24</span> <span style="color: rgba(0, 0, 0, 1)">                  init(target, data);
</span><span style="color: rgba(0, 128, 128, 1)">25</span> <span style="color: rgba(0, 0, 0, 1)">                });
</span><span style="color: rgba(0, 128, 128, 1)">26</span> <span style="color: rgba(0, 0, 0, 1)">            }
</span><span style="color: rgba(0, 128, 128, 1)">27</span>
<span style="color: rgba(0, 128, 128, 1)">28</span>             <span style="color: rgba(0, 0, 255, 1)">function</span><span style="color: rgba(0, 0, 0, 1)"> init(target, data) {
</span><span style="color: rgba(0, 128, 128, 1)">29</span>               $.each(data, <span style="color: rgba(0, 0, 255, 1)">function</span><span style="color: rgba(0, 0, 0, 1)"> (i, item) {
</span><span style="color: rgba(0, 128, 128, 1)">30</span>                     <span style="color: rgba(0, 0, 255, 1)">var</span> option = $('&lt;option&gt;&lt;/option&gt;'<span style="color: rgba(0, 0, 0, 1)">);
</span><span style="color: rgba(0, 128, 128, 1)">31</span>                     option.attr('value'<span style="color: rgba(0, 0, 0, 1)">, item);
</span><span style="color: rgba(0, 128, 128, 1)">32</span> <span style="color: rgba(0, 0, 0, 1)">                  option.text(item);
</span><span style="color: rgba(0, 128, 128, 1)">33</span> <span style="color: rgba(0, 0, 0, 1)">                  target.append(option);
</span><span style="color: rgba(0, 128, 128, 1)">34</span> <span style="color: rgba(0, 0, 0, 1)">                });
</span><span style="color: rgba(0, 128, 128, 1)">35</span> <span style="color: rgba(0, 0, 0, 1)">                options.onLoadSuccess.call(target);
</span><span style="color: rgba(0, 128, 128, 1)">36</span> <span style="color: rgba(0, 0, 0, 1)">            }
</span><span style="color: rgba(0, 128, 128, 1)">37</span>             target.unbind("change"); target.on("change", <span style="color: rgba(0, 0, 255, 1)">function</span> (e) { <span style="color: rgba(0, 0, 255, 1)">if</span> (options.onChange) <span style="color: rgba(0, 0, 255, 1)">return</span> options.onChange(target.val()); }); } $.fn.combobox.methods = { getValue: <span style="color: rgba(0, 0, 255, 1)">function</span> (jq) { <span style="color: rgba(0, 0, 255, 1)">return</span> jq.val(); }, setValue: <span style="color: rgba(0, 0, 255, 1)">function</span> (jq, param) { jq.val(param); }, load: <span style="color: rgba(0, 0, 255, 1)">function</span> (jq, url) { ('&lt;option&gt;&lt;/option&gt;'); option.attr('value', ''); option.text('请选择'); jq.append(option); ('&lt;option&gt;&lt;/option&gt;'); option.attr('value', item); option.text(item); jq.append(option); }); }); } }; $.fn.combobox.defaults = { url: <span style="color: rgba(0, 0, 255, 1)">null</span>, param: <span style="color: rgba(0, 0, 255, 1)">null</span>, data: <span style="color: rgba(0, 0, 255, 1)">null</span>, valueField: 'value', textField: 'text', placeholder: '请选择', onBeforeLoad: <span style="color: rgba(0, 0, 255, 1)">function</span> (param) { }, onLoadSuccess: <span style="color: rgba(0, 0, 255, 1)">function</span> () { }, onChange: <span style="color: rgba(0, 0, 255, 1)">function</span><span style="color: rgba(0, 0, 0, 1)"> (value) { }
</span><span style="color: rgba(0, 128, 128, 1)">38</span> <span style="color: rgba(0, 0, 0, 1)">            };
</span><span style="color: rgba(0, 128, 128, 1)">39</span>             })(jQuery);</pre>
</div>
<p>&nbsp;&nbsp;&nbsp; 调用的时候</p>
<div class="cnblogs_code">
<pre><span style="color: rgba(0, 128, 128, 1)">1</span>$("#sel_search_orderstatus"<span style="color: rgba(0, 0, 0, 1)">).combobox({
</span><span style="color: rgba(0, 128, 128, 1)">2</span>               url: '/apiaction/Order/OrderApi/GetOrderStatu'<span style="color: rgba(0, 0, 0, 1)">,
</span><span style="color: rgba(0, 128, 128, 1)">3</span>               valueField: 'VALUE'<span style="color: rgba(0, 0, 0, 1)">,
</span><span style="color: rgba(0, 128, 128, 1)">4</span>               textField: 'NAME'
<span style="color: rgba(0, 128, 128, 1)">5</span>             });</pre>
</div>
<p>就能自动从后台取数据,注意valueField和textField对应要显示和实际值。</p>
<p><br><span style="font-size: 15px"><strong><span style="background-color: rgba(255, 204, 0, 1)">十五、自己写过多线程组件吗?简要说明!</span></strong></span><br>出现指数:三颗星<br>主要考点:此题是两年前博主在携程的一次电话面试中遇到的,其他地方基本上没遇到过,其实到现在也不能理解当时面试官问这个问题的目的。但我想,此问题必有出处,估计面试官是想了解你对多线程以及线程池等的理解深度。</p>
<p><span style="font-size: 18pt"><strong><span style="background-color: rgba(255, 0, 0, 1)">知识点:</span></strong></span><br><strong><span style="background-color: rgba(255, 204, 0, 1)">1、什么是面向对象?</span></strong><br>面向对象说到底就是一种思想,任何事物都可以看作是一个对象。在有些面试题目中也称之为OOP(Object Oriented Programming)。分开来解读就是:<br>Object:对象<br>Oriented: 面向的<br>Programming:程序设计<br>面向对象就是把一个人或事务的属性,比如名字,年龄这些定义在一个实体类里面。存和取的时候直接使用存取实体类就把这个人的名字,年龄这些全部存了,这个实体类就叫对象,这种思想就叫面向对象。<br>面向对象开发具有以下优点:<br>&nbsp;&nbsp;&nbsp; 代码开发模块化,便于维护。<br>&nbsp;&nbsp;&nbsp; 代码复用性强<br>&nbsp;&nbsp;&nbsp; 代码的可靠性和灵活性。<br>&nbsp;&nbsp;&nbsp; 代码的可读性和可扩展性。</p>
<p><br><span style="background-color: rgba(255, 204, 0, 1)"><strong>2. 简述 private、 protected、 public、 internal 修饰符的访问权限。</strong></span><br>答 . private : 私有成员, 在类的内部才可以访问。<br>&nbsp;&nbsp;&nbsp;&nbsp; protected : 保护成员,该类内部和继承类中可以访问。<br>&nbsp;&nbsp;&nbsp;&nbsp; public : 公共成员,完全公开,没有访问限制。<br>&nbsp;&nbsp;&nbsp;&nbsp; internal: 在同一命名空间内可以访问,当前程序集内可以访问</p>
<p><br><strong><span style="background-color: rgba(255, 204, 0, 1)">3 .列举ASP.NET 页面之间传递值的几种方式。</span></strong><br>答. 1.Request.QueryString<br>&nbsp;&nbsp; &nbsp;2.Request.Form<br>&nbsp;&nbsp; &nbsp;3.Session<br>&nbsp;&nbsp; &nbsp;4.Application<br>&nbsp;&nbsp; &nbsp;5.Cache<br>&nbsp;&nbsp; &nbsp;6.Cookie<br>&nbsp;&nbsp; &nbsp;7.Server.Transfer<br>&nbsp;&nbsp; &nbsp;8.Database<br>&nbsp;&nbsp; &nbsp;9.HttpContext的Item属性等</p>
<p><br><span style="background-color: rgba(255, 204, 0, 1)"><strong>4.a=10,b=15,请在不使用第三方变量的情况下,把a、b的值互换</strong></span><br>答: int a=a+b; int b=a-b;int a=a-b;</p>
<p><br><span style="background-color: rgba(255, 204, 0, 1)"><strong>5.用.net做B/S结构的系统,您是用几层结构来开发,每一层之间的关系以及为什么要这样分层?</strong></span><br>答:一般为3层:数据访问层,业务层,表示层。<br>数据访问层对数据库进行增删查改。<br>业务层一般分为二层,业务表观层实现与表示层的沟通,业务规则层实现用户密码的安全等。<br>表示层为了与用户交互例如用户添加表单。<br>优点: 分工明确,条理清晰,易于调试,而且具有可扩展性。<br>缺点: 增加成本。</p>
<p><br><strong><span style="background-color: rgba(255, 204, 0, 1)">6.能用foreach遍历访问的对象需要实现 ________________接口或声明________________方法的类型。</span></strong><br>答:IEnumerable 、 GetEnumerator。</p>
<p><br><strong><span style="background-color: rgba(255, 204, 0, 1)">7.GC是什么? 为什么要有GC?</span></strong><br>答:GC是垃圾收集器。程序员不用担心内存管理,因为垃圾收集器会自动进行管理。要请求垃圾收集,可以调用下面的方法之一:<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; System.gc()<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Runtime.getRuntime().gc()</p>
<p><br><strong><span style="background-color: rgba(255, 204, 0, 1)">8.启动一个线程是用run()还是start()?</span></strong><br>答:启动一个线程是调用start()方法,使线程所代表的虚拟处理机处于可运行状态,这意味着它可以由JVM调度并执行。这并不意味着线程就会立即运行。run() 方法可以产生必须退出的标志来停止一个线程。</p>
<p><br><span style="background-color: rgba(255, 204, 0, 1)">9.是否可以继承String类?</span><br>答:String类是final类故不可以继承。</p>
<p><br><span style="background-color: rgba(255, 204, 0, 1)"><strong>10.session喜欢丢值且占内存,Cookis不安全,请问用什么办法代替这两种原始的方法</strong></span><br>答:redis 或者 memcache。当然,微软也提供了解决方案。iis中由于有进程回收机制,系统繁忙的话Session会丢失,可以用Sate server或SQL Server数据库的方式。</p>
<p><br><strong><span style="background-color: rgba(255, 204, 0, 1)">11.IOC容器?</span></strong><br>1. IOC即控制反转,是一种设计思想,在之前的项目中,当我们需要一个对象时,需要new一个对象,而IOC的设计思想是我们将需要的对象注入到一个容器中,就会获得我们所需要的资源 。<br>2. IOC和DI IOC是控制反转,DI是依赖注入,控制反转的解释有些模棱两可,而依赖注入就很明确,我们将需要的对象注入到容器中,获取所需要的资源。<br>3. IOC控制反转:正常情况下程序开发是上端调用下端,依赖下端,依赖倒置原则告诉我们,上端不要依赖下端,要依赖抽象,上端只依赖抽象,细节交给第三方工厂(容器)来决定,这就是IOC,就是控制反转——使系统架构可以更稳定,支持扩展。</p>
<p><br><strong><span style="background-color: rgba(255, 204, 0, 1)">12、什么是委托,事件是不是一种委托?</span></strong><br>1. 委托可以把一个方法作为参数代入另一个方法。<br>2. 委托可以理解为指向一个函数的引用。<br>3. 事件是一种特殊的委托。<br>delegate &lt;函数返回类型&gt; &lt;委托名&gt; (&lt;函数参数&gt;)</p>
<p><br><strong><span style="background-color: rgba(255, 204, 0, 1)">13.c#多线程是什么?</span></strong><br>多线程的优点:可以同时完成多个任务;可以使程序的响应速度更快;可以节省大量时间进行处理任务;可以随时停止任务;可以设置每个任务的优先级,以优化程序性能。</p>
<p><br><strong><span style="background-color: rgba(255, 204, 0, 1)">14.WebApi概述</span></strong><br>Web API是在.NET Framework之上构建的Web的API的框架,Web API是一个编程接口,用于操作可通过标准HTTP方法和标头访问的系统,Web API需要基于.NET 3.5或更高版本才可以进行开发</p>
<p><br><strong><span style="background-color: rgba(255, 204, 0, 1)">15.什么是WebService</span></strong><br>webservice是一种跨平台,跨语言的规范,用于不同平台,不同语言开发的应用之间的交互,是基于网络的、分布式的模块化组件,它执行特定的任务,遵守具体的技术规范。</p>
<p><br><strong><span style="background-color: rgba(255, 204, 0, 1)">16.存储过程是什么?有什么用?有什么优点?用什么来调用?</span></strong><br>存储过程是预编译,安全性高,也是大大提高了效率,存储过程可以重复使用以减少数据库开发人员的工作量,复杂的逻辑我们可以使用存储过程完成,在存储过程中我们可以使用临时表,还可以定义变量,拼接sql语句,调用时,只需执行这个存储过程名,传入我们所需要的参数即可。</p>
<p><strong><span style="background-color: rgba(255, 204, 0, 1)">17.何为触发器?</span></strong><br>触发器是一种特殊的存储过程,主要是通过事件触发而被执行。它可以强化约束来维护数据的完整性和一致性,可以跟踪数据库内的操作从而不允许未经许可的更新和变化。可以级联运算。<br>常见的触发器有三种:分别应用于Insert , Update , Delete 事件。</p>
<p><br><strong><span style="background-color: rgba(255, 204, 0, 1)">18.什么叫做泛型?</span></strong><br>只是为了去掉重复代码,应对不同类型的共同需求。</p>
<p><br><strong><span style="background-color: rgba(255, 204, 0, 1)">19. C#中值类型和引用类型分别有哪些? </span></strong><br>值类型:结构体(数值类型,bool型,用户定义的结构体),枚举,可空类型。<br>引用类型:数组,用户定义的类、接口、委托,object,字符串。</p>
<p><br><strong><span style="background-color: rgba(255, 204, 0, 1)">21 .NET的错误处理机制是什么?</span></strong><br>.net错误处理机制采用try-&gt;catch-&gt;finally结构,发生错误时,层层上抛,直到找到匹配的Catch为止。</p>
<p><br><strong><span style="background-color: rgba(255, 204, 0, 1)">22.C#可否对内存进行直接的操作?</span></strong><br>在.net下,.net引用了垃圾回收(GC)功能,它替代了程序员不过在C#中,不能直接实现Finalize方法,而是在析构函数中调用基类的Finalize()方法。</p>
<p><br><strong><span style="background-color: rgba(255, 204, 0, 1)">23. ADO.NET相对于ADO等主要有什么改进?</span></strong><br>1:ado.net不依赖于ole db提供程序,而是使用.net托管提供的程序,<br>2:不使用com<br>3:不在支持动态游标和服务器端游<br>4:,可以断开connection而保留当前数据集可用<br>5:强类型转换<br>6:xml支持</p>
<p><br><span style="background-color: rgba(255, 204, 0, 1)"><strong>24.如果在一个B/S结构的系统中需要传递变量值,但是又不能使用Session、Cookie、Application,您有几种方法进行处理?</strong></span><br>this.Server.Transfer、Response.Redirect()、QueryString</p>
<p><br><strong><span style="background-color: rgba(255, 204, 0, 1)">25. .NET中读写数据库需要用到那些类?他们的作用?</span></strong><br>Connection连接对象,Command执行命令和存储过程,DataReader向前只读的数据流,DataAdapter适配器,支持增删查询,DataSet数据级对象,相当与内存里的一张或多张表。</p>
<p><br><strong><span style="background-color: rgba(255, 204, 0, 1)">26.简要谈一下您对微软.NET架构下remoting和webservice两项技术的理解以及实际中的应用。</span></strong><br>WS主要是可利用HTTP,穿透防火墙。而Remoting可以利用TCP/IP,二进制传送提高效率。<br>remoting是.net中用来跨越machine,process, appdomain进行方法调用的技术,对于三成结构的程序,就可以使用remoting技术来构建.它是分布应用的基础技术.相当于以前的DCOM。<br>Web Service是一种构建应用程序的普通模型,并能在所有支持internet网通讯的操作系统上实施。Web Service令基于组件的开发和web的结合达到最佳,基于组件的对象模型。</p>
<p><br><strong><span style="background-color: rgba(255, 204, 0, 1)">27.什么是反射?</span></strong><br>动态获取程序集信息。</p>
<p><br><strong><span style="background-color: rgba(255, 204, 0, 1)">28.override与重载的区别?</span></strong><br>重载是方法的名称相同。参数或参数类型不同,进行多次重载以适应不同的需要。<br>Override是子类对基类中函数的重写。为了适应需要。</p>
<p><br><strong><span style="background-color: rgba(255, 204, 0, 1)">29.装箱和拆箱的概念和原理</span></strong><br>装箱是将值类型转化为引用类型的过程;<br>拆箱是将引用类型转化为值类型的过程</p>
<p><br><span style="background-color: rgba(255, 204, 0, 1)"><strong>30.Session有什么重大BUG,微软提出了什么方法加以解决?</strong></span><br>是iis中由于有进程回收机制,系统繁忙的话Session会丢失,可以用Sate server或SQL Server数据库的方式存储Session不过这种方式比较慢,而且无法捕获Session的END事件。</p>
<p>&nbsp;</p>
<p>参考文献:https://blog.csdn.net/user2041/article/details/80591365</p><br><br>
来源:https://www.cnblogs.com/guozhaoxin/p/11959196.html
頁: [1]
查看完整版本: ASP.NET(C#) 面试总结面试题大全