Interview Questions
C#
1. How do you inherit from a class in C#? Place a colon and then the name of the base class. Notice that it’s double colon in C++.
2. Does C# support multiple inheritance? No, use interfaces instead.
3. When you inherit a protected class-level variable, who is it available to? Classes in the same namespace.
4. Are private class-level variables inherited? Yes, but they are not accessible, so looking at it you can honestly say that they are not inherited. But they are.
5. What’s the top .NET class that everything is derived from? System.Object.
6. How’s method overriding different from overloading? When overriding, you change the method behavior for a derived class. Overloading simply involves having a method with the same name within the class.
7. What does the keyword virtual mean in the method definition? The method can be over-ridden.
8. Can you prevent your class from being inherited and becoming a base class for some other classes? Yes, that’s what keyword sealed in the class definition is for. The developer trying to derive from your class will get a message: cannot inherit from Sealed class WhateverBaseClassName. It’s the same concept as final class in Java.
9. Can you allow class to be inherited, but prevent the method from being over-ridden? Yes, just leave the class public and make the method sealed.
10. When do you absolutely have to declare a class as abstract (as opposed to free-willed educated choice or decision based on UML diagram)? When at least one of the methods in the class is abstract. When the class itself is inherited from an abstract class, but not all base abstract methods have been over-ridden.
11. What’s an abstract class? A class that cannot be instantiated. A concept in C++ known as pure virtual method. A class that must be inherited and have the methods over-ridden. Essentially, it’s a blueprint for a class without any implementation.
12. What’s an interface class? It’s an abstract class with public abstract methods all of which must be implemented in the inherited classes.
13. What’s the difference between an interface and abstract class? In the interface all methods must be abstract; in the abstract class some methods can be concrete. In the interface no accessibility modifiers are allowed, which is ok in abstract classes.
14. What’s the difference between System.String and System.StringBuilder classes? System.String is immutable; System.StringBuilder was designed with the purpose of having a mutable string where a variety of operations can be performed.
15. What’s the advantage of using System.Text.StringBuilder over System.String? StringBuilder is more efficient in the cases, where a lot of manipulation is done to the text. Strings are immutable, so each time it’s being operated on, a new instance is created.
16. Can you store multiple data types in System.Array? No.
17. What’s the difference between the System.Array.CopyTo() and System.Array.Clone()? The first one performs a deep copy of the array, the second one is shallow.
18. How can you sort the elements of the array in descending order? By calling Sort() and then Reverse() methods.
19. What’s the .NET datatype that allows the retrieval of data by a unique key? HashTable.
20. Will finally block get executed if the exception had not occurred? Yes.
21. Why is it a bad idea to throw your own exceptions? Well, if at that point you know that an error has occurred, then why not write the proper code to handle that error instead of passing a new Exception object to the catch block? Throwing your own exceptions signifies some design flaws in the project.
22. How’s the DLL Hell problem solved in .NET? Assembly versioning allows the application to specify not only the library it needs to run (which was available under Win32), but also the version of the assembly.
23. What’s a satellite assembly? When you write a multilingual or multi-cultural application in .NET, and want to distribute the core application separately from the localized modules, the localized assemblies that modify the core application are called satellite assemblies.
24. How do you generate documentation from the C# file commented properly with a command-line compiler? Compile it with a /doc switch.
25. Is XML case-sensitive? Yes, so
26. What are three test cases you should go through in unit testing? 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. Explain the three services model (three-tier application). Presentation (UI), business (logic and underlying code) and data (from storage or other sources).
28. What are advantages and disadvantages of Microsoft-provided data provider classes in ADO.NET? SQLServer.NET data provider is high-speed and robust, but requires SQL Server license purchased from Microsoft. OLE-DB.NET is universal for accessing other sources, like Oracle, DB2, Microsoft Access and Informix, but it’s a .NET layer on top of OLE layer, so not the fastest thing in the world. ODBC.NET is a deprecated layer provided for backward compatibility to ODBC engines.
29. What’s the role of the DataReader class in ADO.NET connections? It returns a read-only dataset from the data source when the command is executed.
30. What connections does Microsoft SQL Server support? Windows Authentication (via Active Directory) and SQL Server authentication (via Microsoft SQL Server username and passwords).
31. Which one is trusted and which one is untrusted? Windows Authentication is trusted because the username and password are checked with the Active Directory, the SQL Server authentication is untrusted, since SQL Server is the only verifier participating in the transaction.
Given the following methods of the ASP .Net Page class, in which of them would you attach an event handler to an event published by a control on the web page?
a. OnLoad()
b. Page_Loader()
c. OnInit()
d. OnPostBack()
Choice C is the correct answer. You should attach event handlers to events before any other code is executed. Since the OnInit() method is called when an ASP.Net page is initialized, this would be the most appropriate place to attach an event to its event handler. The remaining
choices A, B and D are incorrect because other code would be used prior to the events being attached to their event handlers.
Which is the most appropriate place to install a Strong-Named assembly that is intended for use among several web applications?
a. A. GAC on the local area network Primary Domain Controller (PDC) server.
b. B. The Global Assembly Cache on the Web Server.
c. C. The solution's /bin directory.
d. D. The Virtual Directory of the ASP.Net Web Application
Choice B is the correct answer. You would install a Strong-Named assembly in the Global Assembly Cache of the Web Server. It would not work for the Strong-Named assembly to be installed on a PDC server, unless that were, also, the web server. The solution's /bin directory or the virtual directory would not be places to install a Strong-Named assembly that is to be shared among several web applications.
Why would you use a SqlConnection object instead of an OleDbConnection object?
a. A SqlConnection object is optimized for use with SQL Server.
b. A SqlConnection object can be used for any type of database.
c. A SqlConnection object can be used with DataSets while an OleDbConnection cannot.
d. A SqlConnection object can be used with DataView objects and an OleDbConnection object, cannot.
Choice A is the correct answer. Although a SqlConnection object is optimized for use with SQL Server while an OleDbConnection can be used for most types of databases, OleDbConnection objects require additional overhead. SqlConnection objects contain a lower level of abstraction than OleDbConnection objects by bypassing the OleDb layer, and for that reason they tend to be much faster. They are optimized for use with SQL Server 7.0 and SQL Server 2000 databases.
SqlConnection object can only be used for connections to SQL Server 7.0 and SQL Server 2000 databases at this time, so choice B is incorrect. Both SqlConnection objects and OleDbConnection objects can be used with DataSet objects. DataView objects are used with DataSet objects to provide various views of the data, so choice D is not relevant to this question.
Which of the following statements would you use to properly describe unit testing?
a. Test and fix the errors.
b. With carefully planned test data, run the module to see if it works according to its specifications.
c. With carefully planned test data, run a module to see if it integrates well with other modules.
d. Testing performed by users, just before the Web Application is released.
Choice B is the correct answer. With carefully planned test data, run the module to see if it works according to its specifications. By running just the one module, you are able to see if its methods and properties perform as specified.
When testing and fixing errors, you are debugging, so choice A is incorrect. Choice C is incorrect because this is a description of integration testing. Choice D is incorrect because unit testing is usually performed by developers.
You have several users with Windows user accounts who are using your new ASP.Net web application to retrieve data from the SQL Server 2000 database. Each user connects to the database using his/her user account. There are now several hundred users, using the data. How can you improve performance of the web application?
a. Use SQL Server authentication.
b. Use the same connection string for the database connections.
c. Use Basic authentication.
d. Stop using the database to retrieve the data.
Choice Choice B is the correct answer. If you use the same connection string for all users, including usernames and passwords, you will enable connection pooling, thus improving performance.
Using SQL Server authentication or Basic authentication will not improve performance. Using SQL Server authentication or Basic authentication will not have as much, if any effect on performance, so choices A and C are incorrect. Obviously, choice D is incorrect because you cannot stop using the database.
Which of the following is an authentication method for an ASP.Net web application?
a. Custom
b. None
c. Anonymous Authorization
d. Authorization
Choice A is the correct answer. Custom authentication is used on web applications where it is necessary, but it is very difficult to incorporate and manage.
None is not a form of authentication and Anonymous Authorization is not, either, so choices B and C are incorrect. Choice D is incorrect because authorization is not a form of authentication; rather it provides authenticated users the permissions required to access network resources.
You have created a new ASP.Net web application. You build the solution in Visual Studio .Net. You notice that there is a /bin directory under the virtual directory. Which type of files should you place in this location?
a. Assemblies that are used on only this one web application.
b. Assemblies that are used on web sites on only this web server machine.
c. Assemblies that are used by web applications anywhere on the network.
d. Assemblies that are XCOPY'd to the location.
Choice A is the correct answer. Only assemblies that are to be used on this one single web application should reside in the /bin directory of a web application. If the assembly is to be shared among several applications, it should be installed in the GAC of the machine where it is to be used.
Security is very important on any web site. By default, a .Net web site is configured with which of the following authentication types?
a. IIS Anonymous
b. Windows Forms
c. Windows 2000
d. Windows
e. Basic
Choice A is the correct answer. Whenever a request is received by the web server, IIS first checks to see if the request came from an authorized ip address. If so, then, IIS checks to see if the user is authorized to access the web server. By default IIS is set to anonymous access.
You need to display the sales data for your division for the past 5 years in a DataGrid on a Web Form. Performance is very important. What would be the best strategy to use in retrieving the data?
a. Use a DataReader object to retrieve the data for the DataGrid.
b. Use a DataSet object to retrieve the data for the DataGrid.
c. Use a simple select statement as the data source for the DataGrid.
d. Use a cached XML file as the data source and retrieve the data with a DataSet.
Choice A is the correct answer. The most efficient method of data retrieval when the data simply has to be displayed is a DataReader object.