C# Interview Question

最近又要找工作了,整理一些网上的C# .NET SQL  的面试题:

1. Q: How can you tell the application to look for assemblies at the locations other than its own install?

    A: Use the directive in the XML .Config file fot a given application.

   < probing privatePath=C:/mylibs; bin/debug />

2. Q: How can you debug failed assembly binds?

    A: Use the Assembly Binding Log Viewer (fuslogvw.exe) to find out the paths searched.

3. Q: Where are shared assemblies stored?

    A: The GAC - Global assembly cache. Which would be the C:/Windows/assembly for Win7 X64.

4. Q: How can you create a strong name for a .NET assembly?

    A: With the help of Strong Name Tool (sn.exe).

5. Q: What is delay signing?

    A: Delay signing allows you to place a shared assembly in the GAC by signing the assembly with just the public key. This allows the assembly to be signed with the private key at a later stage, when the development process is complete and the component or assembly is ready to be deployed. This process enables developers to work with shared assemblies as if they were strongly named, and it secures the private key of the signature from being accessed at different stages of development.

6. Q: Is there an equivalent of exit() for quitting a C# .NET application?

    A: System.Environment.Exit(int exitCode) & Application.Exit();

7. Q: Can you prevent your class from being inherited and becoming a base class for some other classes?

    A: Use keyword: sealed in class definition. The same as final class in JAVA.

8. Q: How do I make a DLL in C#?

    A: Use the /Target:library compiler option.

9. Q: Is there a way to force garbage collection?

    A: Yes. Set all references to null and then call System.GC.Collect(). If you need to have some objects destructed, and System.DC.Collect() doesn't seem to be doing it for you, you can force finalizers to be run by setting all the references to the object to null and then calling System.GC.RunFinalizers().

10. Q: What connections does Microsoft SQL Server support?

    A: Windows Authentication (via Active Directory) and SQL Server authentication (via Microsoft SQL Server username and passwords).

11. Q: How do I register my code for use by classic COM clients?

    A: Use the regasm.exe utility to generate a type library and the necessary entries in the Windows Registry to make a class available to classic COM clients.

12. Q: Where is the output of TextWriterTraceListener redirected?

    A: To the Console or a text file depending on the parameter passed to the constructor.

13. Q: Why cannot you specify the accessibility modifier for methods inside the interface?

    A: They all must be public

14. Q: Is it possible to restrict the scope of a field/method of a class to the classes in the same namespace?

    A: There is no way to restrict to a namespace. Namespaces are never units of protection. But if you're using assemblies, you can use the "internal" access modifier to restrict access to only within the assembly.

15. Q: What is the difference between the System.Array.CopyTo() and System.Array.Clone()?

    A: CopyTo performs a deep copy of the array, Clone is shallow.

16. Q: How do I declare inout arguments in C#?

    A: using "ref".

17. Q: What is the difference between const and static read-only?

    A: The static read-only can be modified by the containing class, but the const can never be modified and must be initialized to a compile time constant.

18. Q: What is the difference between System.String and System.StringBuilder classes?

    A: System.String is immutable; System.StringBuilder was designed with the purpose of having a mutable string where a variety of operations can be performed.

19. Q: What is the top .NET class that everything is derived from?

    A: System.Object.

20. Q: Can you allow class to be inherited, but prevent the method from being over-ridden?

    A: class public method sealed.

21. Q: Are private class-level variables inherited?

    A: Yes. But they are not accessible.

22. Q: Can you inherit multiple interfaces?

    A: Yes. .NET does support multiple interfaces.

23. Q: What namespaces are necessary to create a localized application?

    A: System.Globalization, System.Resources.

24. Q: What is the advantage of using System.Text.StringBuilder over System.String?

    A: Strings are immutable, so each time it is being operated on, a new instance is created.

25: Some sample code follows: using System;

using System.Threading;
class ThreadTest
{
public void runme()
{
Console.WriteLine("Runme Called");
}
public static void Main(String[] args)
{
ThreadTest b = new ThreadTest();
Thread t = new Thread(new ThreadStart(b.runme));
t.Start();
}
}
26. Q: What are three test cases you should go through in unit testing?
A: Positive test cases (correct data, correct output), negative test cases
(broken or missing data, proper handling), exception test cases
(exceptions are thrown and caught properly).

27. Q: Does C# support #define for defining global constants?

    A: No. If you want to get something that works like the following C code:
#define A 1
use the following C# code: class MyConstants
{
     public const int A = 1;
}

28. Q: Does C# support templates?

    A: No. These generic types have similar syntax but are instantiated at run time as opposed to compile time.

29. Q: Does C# support parameterized properties?

    A: No. C# does, however, support the concept of an indexer from language spec. An indexer is a member that enables an object to be indexed in the same way as an array. Whereas properties enable field-like access, indexers enable array-like access.

30. Q: Does C# support C type macros?

    A: No.

 

To BE CONTINUED......

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值