What Great .NET Developers Ought To Know (More .NET Interview Questions

A while back, I posted a list of ASP.NET Interview Questions. Conventional wisdom was split, with about half the folks saying I was nuts and that it was a list of trivia. The others said basically "Ya, those are good. I'd probably have to look a few up." To me, that's the right response.

Certainly I wasn't trying to boil all of .NET Software Development down to a few simple "trivia" questions. However, I WAS trying to get folks thinking. I believe that really good ASP.NET (and for that matter, WinForms) is a little [read: lot] more than just draging a control onto a designer and hoping for the best. A good race driver knows his car - what it can do and what it can't.

So, here's another list...a greatly expanded list, for your consumption (with attribution). I wrote this on a plane last week on the way from Boise to Portland. I tried to take into consideration the concerns that my lists contain unreasonable trivia. I tried to make a list that was organized by section. If you've never down ASP.NET, you obviously won't know all the ASP.NET section. If you're an indenpendant consultant, you may never come upon some of these concepts. However, ever question here has come up more than once in the last 4 years of my time at Corillian. So, knowing groking these questions may not make you a good or bad developer, but it WILL save you time when problems arise. 

What Great .NET Developers Ought To Know

Everyone who writes code

  • Describe the difference between a Thread and a Process?

线程(Thread)与进程(Process)二者都定义了某种边界,不同的是进程定义的是应用程序与应用程序之间的边界,不同的进程之间不能共享代码和数据空间,而线程定义的是代码执行堆栈和执行上下文的边界。一个进程可以包括若干个线程,同时创建多个线程来完成某项任务,便是多线程。而同一进程中的不同线程共享代码和数据空间。用一个比喻来说,如果一个家庭代表一个进程,在家庭内部,各个成员就是线程,家庭中的每个成员都有义务对家庭的财富进行积累,同时也有权利对家庭财富进行消费,当面对一个任务的时候,家庭也可以派出几个成员来协同完成,而家庭之外的人则没有办法直接消费不属于自己家庭的财产。

  • What is a Windows Service and how does its lifecycle differ from a "standard" EXE?

Windows服务是运行在windows后台指定用户下(默认System)的应用程序,它没有标准的UI界面,想比标准的EXE程序,Windows服务是在服务开始的时候创建,而在服务结束的时候销毁,而且可以设置服务是否与操作系统一起启动,一起关闭。它支持三种方式:1)自动方式 2)手动方式 3)禁用 。自动方式的时候,windows服务将在OS启动后自动启动运行,而手动方式则必须手工启动服务,禁用的情况下服务将不能被启动。另外标准的EXE默认使用的当前登录的用户,而windows服务则默认使用System用户,这在对系统资源访问的时候特别需要注意。

  • What is the maximum amount of memory any single process on Windows can address? Is this different than the maximum virtual memory for the system? How would this affect a system design?

这个需要针对硬件平台,公式为单个进程能访问的最大内存量=2的处理器位数次方/2,比如通常情况下,32位处理器下,单个进程所能访问的最大内存量为:232 /2 = 2G 。虚拟内存是系统可以提供的内存量。所以,线程能访问2G空间,但是如果系统虚拟内存不足2G也会发生内存溢出。当然,一般的应用程序不会使用这么多内存。

  • What is the difference between an EXE and a DLL?

执行exe文件的时候,系统会给其分配运行空间。

  • What is strong-typing versus weak-typing? Which is preferred? Why?

强类型是在编译的时候就确定类型的数据,在执行时类型不能更改,而弱类型在执行的时候才会确定类型。没有好不好,二者各有好处,强类型安全,因为它事先已经确定好了,而且效率高。一般用于编译型编程语言,如c++,java,c#,pascal等,弱类型相比而言不安全,在运行的时候容易出现错误,但它灵活,多用于解释型编程语言,如javascript,vb等

  • Corillian's product is a "Component Container." Name at least 3 component containers that ship now with the Windows Server Family.
  • What is a PID? How is it useful when troubleshooting a system?

PID是进程编号,在系统发现故障的时候,可以根据它寻找故障所发生的具体进程,并且可通过visual studio.net等ide将故障进程附加到进程中进行调试(debug)

  • How many processes can listen on a single TCP/IP port?

可以为多个,多个为端口复用。

  • What is the GAC? What problem does it solve?

Gloal Assembly Cache,全局应用程序集缓存。它解决了几个程序共享某一个程序集的问题。实际上就是.net将强命名的程序集按照一定得层次结构组织,这可以解决传说中的Dll Hell。(实际上牺牲了简单部署)

 

Mid-Level .NET Developer

  • Describe the difference between Interface-oriented, Object-oriented and Aspect-oriented programming.

面向接口更关注的是概念,它的原则是先定义好行为规范,再根据行为规范创建实现,严格的来说,面向接口应该是面向对象中的一部分吧,因为面向对象也强调的是依赖倒置原则,也就是实现依赖于抽象,而抽象不依赖于具体实现,更具比较的应该是面向接口与面向抽象对象,我的体会是面向接口更加灵活,但实现时候,稍微有些代码冗余,而面向抽象可以结合面向接口,先定义接口,再定义抽象类,在抽象类中处理一些公共逻辑,再实现具体实现类。面向对象是对复杂问题的分解。面向方面的编程是一种新概念,它解决了很多面向对象无法解决的问题,比如面向对象技术只能对业务相关的代码模块化,而无法对和业务无关的代码模块化。而面向方面正是解决这一问题的方案,它的关键思想是"将应用程序中的商业逻辑与对其提供支持的通用服务进行分离"。

  • Describe what an Interface is and how it’s different from a Class.

接口(Interface)是用来定义行为规范的,不会有具体实现,而抽象类除定义行为规范外,可以有部分实现,但一个类能实现多个接口,但只能继承一个父类。

  • What is Reflection?

程序集包含模块,而模块又包括类型,类型下有成员,反射就是管理程序集,模块,类型的对象,它能够动态的创建类型的实例,设置现有对象的类型或者获取现有对象的类型,能调用类型的方法和访问类型的字段属性。它是在运行时创建和使用类型实例

  • What is the difference between XML Web Services using ASMX and .NET Remoting using SOAP?

Web服务使用的消息机制,而Remoting采用的RPC. Web Service能用于不同平台,不同语言,Remoting只适用于.Net。效率上Remoting高于Xml Web Service

  • Are the type system represented by XmlSchema and the CLS isomorphic?

 

  • Conceptually, what is the difference between early-binding and late-binding?

这个就像是强弱类型的比较相似,前期绑定是在编译的时候就确定了要绑定的数据,而后期绑定是在运行的时候才填充数据。所以前期绑定如果失败,会在编译时报编译错误,而后期绑定失败只有在运行时的时候才发生

  • Is using Assembly.Load a static reference or dynamic reference?

 

  • When would using Assembly.LoadFrom or Assembly.LoadFile be appropriate?

调用LoadFrom加载程序集,这就要求同时将此程序集所依赖的程序集加载进来。而LoadFile就是加载程序集文件的内容,只将传入参数的文件加载,不考虑程序集依赖,但如果有相同实现,但位置不同的文件用LoadFrom是不能同时加载进来的,而LoadFile却可以。由于LoadFile加载的是文件,所以调用它之后,可能因为缺少必要的依赖造成无法被执行。

  • What is an Asssembly Qualified Name? Is it a filename? How is it different?

它不是一个文件名,相比文件名,Assembly Qualified Name(程序集限定名称),更能确定一个程序集,它包含文件名,但同时包含版本,公钥,和区域。因为同样一个名称的文件可能有不同的版本和区域,此时单独靠文件名称,可能会造成不能确定程序集的正确性。

  • Is this valid? Assembly.Load("foo.dll");

错误,正确的应该是Assembly.Load("foo"); 或者Assembly.LoadFrom("foo.dll")。因为Assembly.Load传入的参数是Assembly Name,而不是Assembly File Name。

  • How is a strongly-named assembly different from one that isn’t strongly-named?

强签名的程序集可以做成com,而不做强签名的就不行,同样强签名程序集可以安装到GAC中,而不做强签名的确不能。

  • Can DateTimes be null?

不能,因为其为Struct类型,而结构属于值类型,值类型不能为null,只有引用类型才能被赋值null

  • What is the JIT? What is NGEN? What are limitations and benefits of each?

Just In Time 及时编译,它是在程序第一次运行的时候才进行编译,而NGEN是所谓的pre-jit,就是说在运行前事先就将生成程序集的本机镜像,并保存到全局缓存中,适用NGEN可以提高程序集的加载和执行速度,因为它可以从本机映像中还原数代码和数据结构,而不必像jit那样动态生成它们。感觉和缓存的道理大同小异。

  • How does the generational garbage collector in the .NET CLR manage object lifetime? What is non-deterministic finalization?

1..net垃圾收集器负责管理分配给对象的内存。如果一个对象没有被其他对象或者方法引用,则说明这个对象是一个可回收对象,当垃圾回收线程启动的时候,就会将此对象所占的内存空间释放掉。

2.虽然垃圾回收替我们管理了内存,但是我们没有办法确切的知道内存何时被回收,这就是所谓的non-deterministic finalization。

 

  • What is the difference between Finalize() and Dispose()?

此问题都问烂了,直接略过。

  • How is the using() pattern useful? What is IDisposable? How does it support deterministic finalization?

实现了IDisposiable的类在using中创建,using结束后会自定调用该对象的Dispose方法,释放资源。

  • What does this useful command line do? tasklist /m "mscor*"

列出所有使用了以" mscor"作为开头的dll或者exe的进程和模块信息 (没有考究过)

  • What is the difference between in-proc and out-of-proc?

in-proc是进程内,进程内能共享代码和数据块,out-of-proc是进程外,进程外的互操作需要用进程间通讯来实现。

  • What technology enables out-of-proc communication in .NET?

.Net Remoting技术或者WCF技术。

  • When you’re running a component within ASP.NET, what process is it running within on Windows XP? Windows 2000? Windows 2003?

Xp : aspnet_Wp.exe Windows 2000 : aspnet_Wp.exe Windows 2003 : w3wp.exe 。

 

Senior Developers/Architects

  • What’s wrong with a line like this? DateTime.Parse(myString);

1.由于日期和时间的字符串表示形式必须符合可识别的模式,因此在调用 Parse(String) 方法分析用户输入时,应用程序始终应使用异常处理。或者,可以调用 DateTime..::.TryParse(String, DateTime%) 方法来分析日期和时间字符串并返回一个指示分析操作是否成功的值。

 

2.

由于 Parse(String) 方法尝试使用当前区域性的格式设置规则来分析日期和时间的字符串表示形式,因此尝试跨不同区域性分析特定的字符串可能会失败或返回不同的结果。如果要跨不同的区域设置分析特定的日期和时间格式,请使用 DateTime..::.Parse(String, IFormatProvider) 方法或 ParseExact 方法的重载之一,并提供格式说明符。

 

  • What are PDBs? Where must they be located for debugging to work?

程序数据库(PDB)文件保存着调试和项目状态信息,使用这些信息可以对程序的调试配置进行增量链接。当用    /ZI    或    /Zi    编译    C/C++    程序时或用    /debug    编译    Visual    Basic/C#/JScript    .NET    程序时将创建    PDB    文件。   
Visual    Studio    调试器使用由链接器直接创建的    project.PDB    文件并将此    PDB    的绝对路径嵌入到    EXE    或    DLL    文件中。如果调试器在该位置无法找到    PDB    文件或者如果路径无效(例如,如果项目被移动到了另一台计算机上),调试器将搜索包含    EXE    的路径,即在解决方案的“属性页”中指定的“符号路径”(“调试符号文件”页    ->“通用属性”文件夹)。调试器不会加载与所调试的二进制不匹配的    PDB。

  • What is cyclomatic complexity and why is it important?

圈复杂度。就是表示一个模块的复杂度。具体理论不是很清楚,好像国内提到这个理论的也不多。主要是和一个模块的分支判断有关系。圈复杂度越大,说明模块越容易出错。

  • Write a standard lock() plus “double check” to create a critical section around a variable access.

            if (instance == null)
            {
                lock (staticObject)
                {
                    if (instance == null)
                    {
                        instance = new Program();
                    }
                }
            }

  • What is FullTrust? Do GAC’ed assemblies have FullTrust?

FullTrust权限基本上允许跳过所有的CAS验证,持有该权限的程序集能够访问所有的标准权限。默认情况下,签名程序集的代码只能从拥有FullTrust权限的程序集中调用。这条规则的原因是只有签名程序集可以被放入GAC中并且可能被恶意代码所利用(未签名代码由于位置,功能等无法预测而很难被移动代码利用)。可以通过System.Security.AllowPartiallyTrustedCallersAttributes关闭这一限制。

  • What benefit does your code receive if you decorate it with attributes demanding specific Security permissions?
  • What does this do? gacutil /l | find /i "Corillian"
  • What does this do? sn -t foo.dll

还真是没查到这个命令。汗~

更多内容,可以查看sn.exe的文档。

 

  • What ports must be open for DCOM over a firewall? What is the purpose of Port 135?
  • Contrast OOP and SOA. What are tenets of each?
  • How does the XmlSerializer work? What ACL permissions does a process using it require?
  • Why is catch(Exception) almost always a bad idea?

这样会将所有的异常都进行捕捉。换而言之,一些隐藏的问题会被吞到得不到解决。应当捕捉具体的异常。

  • What is the difference between Debug.Write and Trace.Write? When should each be used?

都是显示调试信息的类。前者只能用在debug mode下,后者两种情况都可以使用。个人认为这个功能定义容易混淆,比较多余。

  • What is the difference between a Debug and Release build? Is there a significant speed difference? Why or why not?

Release版本会讲很多调试信息去掉,

  • Does JITting occur per-assembly or per-method? How does this affect the working set?

JIT在调用方法方法的时候编译IL代码。这样可以避免编译了不需要用的IL代码,某种程度上提高执行效率。

  • Contrast the use of an abstract base class against an interface?
  • What is the difference between a.Equals(b) and a == b?

前者可以根据Equals方法的实现来重新定义比较的逻辑。后者一般指的是对象的引用是否一致的。注意:对与string对象,==指的是里面的字符是否一致,这是因为.net中对字符串的比较做过处理,使得其更符合我们的使用常识。问题来了,如果我们就是想要比较两个字符串的引用是否一致,怎么办?可以将string转型为object,然后进行比较。例如:

object o1 = myString1;

object o2 = myString2;

if(o1== o2)

...

...

 

 

  • In the context of a comparison, what is object identity versus object equivalence?
  • How would one do a deep copy in .NET?

可以将对象序列化以后,再反序列化回内存中。

  • Explain current thinking around IClonable.

提供克隆接口。负责复制对象本身。一般有浅拷贝(MemberwiseClone)和深拷贝(序列化和反序列化)。

  • What is boxing?

将一个值类型对象拷贝到一个object对象所引用的内存中。关键在于存在内存拷贝问题,这就是为什么我们应当避免装箱操做的原因。

  • Is string a value type or a reference type?

引用类型。

  • What is the significance of the "PropertySpecified" pattern used by the XmlSerializer? What problem does it attempt to solve?
  • Why are out parameters a bad idea in .NET? Are they?

按传引用的方式传递参数。会使得参数在调用之后发生变化。这个传参方式可以使用在想返回多个结果的时候。当然,也会引起代码理解的歧义。慎重使用。此外,ref和out的区别于是经常会碰到的一个问题。ref需要传入已经初始化的参数,out不需要。

  • Can attributes be placed on specific parameters to a method? Why is this useful?

C# Component Developers

  • Juxtapose the use of override with new. What is shadowing?
  • Explain the use of virtual, sealed, override, and abstract.
  • Explain the importance and use of each component of this string: Foo.Bar, Version=2.0.205.0, Culture=neutral, PublicKeyToken=593777ae2d274679d
  • Explain the differences between public, protected, private and internal.
  • What benefit do you get from using a Primary Interop Assembly (PIA)?
  • By what mechanism does NUnit know what methods to test?
  • What is the difference between: catch(Exception e){throw e;} and catch(Exception e){throw;}
  • What is the difference between typeof(foo) and myFoo.GetType()?
  • Explain what’s happening in the first constructor: public class c{ public c(string a) : this() {;}; public c() {;} } How is this construct useful?
  • What is this? Can this be used within a static method?

ASP.NET (UI) Developers

  • Describe how a browser-based Form POST becomes a Server-Side event like Button1_OnClick.
  • What is a PostBack?
  • What is ViewState? How is it encoded? Is it encrypted? Who uses ViewState?
  • What is the <machinekey> element and what two ASP.NET technologies is it used for?
  • What three Session State providers are available in ASP.NET 1.1? What are the pros and cons of each?
  • What is Web Gardening? How would using it affect a design?
  • Given one ASP.NET application, how many application objects does it have on a single proc box? A dual? A dual with Web Gardening enabled? How would this affect a design?
  • Are threads reused in ASP.NET between reqeusts? Does every HttpRequest get its own thread? Should you use Thread Local storage with ASP.NET?
  • Is the [ThreadStatic] attribute useful in ASP.NET? Are there side effects? Good or bad?
  • Give an example of how using an HttpHandler could simplify an existing design that serves Check Images from an .aspx page.
  • What kinds of events can an HttpModule subscribe to? What influence can they have on an implementation? What can be done without recompiling the ASP.NET Application?
  • Describe ways to present an arbitrary endpoint (URL) and route requests to that endpoint to ASP.NET.
  • Explain how cookies work. Give an example of Cookie abuse.
  • Explain the importance of HttpRequest.ValidateInput()?
  • What kind of data is passed via HTTP Headers?
  • Juxtapose the HTTP verbs GET and POST. What is HEAD?
  • Name and describe at least a half dozen HTTP Status Codes and what they express to the requesting client.
  • How does if-not-modified-since work? How can it be programmatically implemented with ASP.NET?
    Explain <@OutputCache%> and the usage of VaryByParam, VaryByHeader.
  • How does VaryByCustom work?
  • How would one implement ASP.NET HTML output caching, caching outgoing versions of pages generated via all values of q= except where q=5 (as in http://localhost/page.aspx?q=5)?

Developers using XML

  • What is the purpose of XML Namespaces?
  • When is the DOM appropriate for use? When is it not? Are there size limitations?
  • What is the WS-I Basic Profile and why is it important?
  • Write a small XML document that uses a default namespace and a qualified (prefixed) namespace. Include elements from both namespace.
  • What is the one fundamental difference between Elements and Attributes?
  • What is the difference between Well-Formed XML and Valid XML?
  • How would you validate XML using .NET?
  • Why is this almost always a bad idea? When is it a good idea? myXmlDocument.SelectNodes("//mynode");
  • Describe the difference between pull-style parsers (XmlReader) and eventing-readers (Sax)
  • What is the difference between XPathDocument and XmlDocument? Describe situations where one should be used over the other.
  • What is the difference between an XML "Fragment" and an XML "Document."
  • What does it meant to say “the canonical” form of XML?
  • Why is the XML InfoSet specification different from the Xml DOM? What does the InfoSet attempt to solve?
  • Contrast DTDs versus XSDs. What are their similarities and differences? Which is preferred and why?
  • Does System.Xml support DTDs? How?
  • Can any XML Schema be represented as an object graph? Vice versa?

 

 

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值