General .Net Interview Questions
1) Does C# support multiple-inheritance?
No.
No.
2) Who is a protected class-level variable available to? It is available to any sub-class (a class inheriting this class).
3) Are private class-level variables inherited? Yes, but they are not accessible. Although they are not visible or accessible via the class interface, they are inherited.
4) Describe the accessibility modifier “protected internal”. It
is available to classes that are within the same assembly and derived
from the specified base class. This is a bit tough but if you are
inheriting from a assembly you get these are avaialable.
5) What’s the top .NET class that everything is derived from?
System.Object.
System.Object.
6) What does the term immutable mean?
The data value may not be changed. Note: The variable value may be changed, but the original immutable data value was discarded and a new data value was created in memory.
The data value may not be changed. Note: The variable value may be changed, but the original immutable data value was discarded and a new data value was created in memory.
7) What’s the difference between System.String and System.Text.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.
System.String is immutable. System.StringBuilder was designed with the purpose of having a mutable string where a variety of operations can be performed.
8) What’s the advantage of using System.Text.StringBuilder over System.String?
StringBuilder is more efficient in cases where there is a large amount of string manipulation. Strings are immutable, so each time a string is changed, a new instance in memory is created.
StringBuilder is more efficient in cases where there is a large amount of string manipulation. Strings are immutable, so each time a string is changed, a new instance in memory is created.
9) Can you store multiple data types in System.Array?
No.
No.
10) What’s the difference between the System.Array.CopyTo() and System.Array.Clone()? The
Clone() method returns a new array (a shallow copy) object containing
all the elements in the original array. The CopyTo() method copies the
elements into another existing array. Both perform a shallow copy. A
shallow copy means the contents (each array element) contains references
to the same object as the elements in the original array. A deep copy
(which neither of these methods performs) would create a new instance of
each element's object, resulting in a different, yet identacle object.
11) How can you sort the elements of the array in descending order? By calling Sort() and then Reverse() methods.
12) What’s the .NET collection class that allows an element to be accessed using a unique key? HashTable.
13) What class is underneath the SortedList class? A sorted HashTable.
14) Will the finally block get executed if an exception has not occurred? Yes.
15) What’s the C# syntax to catch any possible exception? A
catch block that catches the exception of type System.Exception. You
can also omit the parameter data type in this case and just write catch
{}.
16) Can multiple catch blocks be executed for a single try statement? No. Once the proper catch block processed, control is transferred to the finally block (if there are any).
17) Explain the three services model commonly know as a three-tier application. Presentation (UI), Business (logic and underlying code) and Data (from storage or other sources).
18) Explain the differences between Server-side and Client-side code?
a) Server
side code will execute at server end all the business logic will
execute at server end where as client side code will execute at client
side at browser end.
19) What is the difference between CType and DirectCast?
a) The
difference between the two keywords is that CType succeeds as long as
there is a valid conversion defined between the expression and the type
and DirectCast requires that the run-time type of an object variable to
be the same as the specified type that it's being cast to. Really the
same, not just that one can be converted to the other.
b) Use
DirectCast if you're absolutely positively sure that an object is the
specified type and the run-time type of the expression are the same. If
you're not sure but expect that the conversion will work, use CType.
The run-time performance of DirectCast is better than that of CType.
However, DirectCast throws an InvalidCastException error if the argument
types do not match, so you must be sure.
Class Questions
1. What is the syntax to inherit from a class in C#? Place a colon and then the name of the base class.
Example: class MyNewClass : MyBaseClass
Example: class MyNewClass : MyBaseClass
2. Can you prevent your class from being inherited by another class? Yes. The keyword “sealed” will prevent the class from being inherited.
3. Can you allow a class to be inherited, but prevent the method from being over-ridden? Yes. Just leave the class public and make the method sealed.
4. What’s an abstract class? A
class that cannot be instantiated. An abstract class is a class that
must be inherited and have the methods overridden. An abstract class is
essentially a blueprint for a class without any implementation.
5. When do you absolutely have to declare a class as abstract?
1. When the class itself is inherited from an abstract class, but not all base abstract methods have been overridden.
2. When at least one of the methods in the class is abstract.
1. When the class itself is inherited from an abstract class, but not all base abstract methods have been overridden.
2. When at least one of the methods in the class is abstract.
6. What is difference between a interface and a class? Interfaces,
like classes, define a set of properties, methods, and events. But
unlike classes, interfaces do not provide implementation. They are
implemented by classes, and defined as separate entities from classes.
7. Why can’t you specify the accessibility modifier for methods inside the interface? They all must be public, and are therefore public by default.
8. Can you inherit multiple interfaces? Yes. .NET does support multiple interfaces.
9. What happens if you inherit multiple interfaces and they have conflicting method names? It’s
up to you to implement the method inside your own class, so
implementation is left entirely up to you. This might cause a problem on
a higher-level scale if similarly named methods from different
interfaces expect different data, but as far as compiler cares you’re
okay.
To Do: Investigate
To Do: Investigate
10. What’s the difference between an interface and abstract class? In
an interface class, all methods are abstract - there is no
implementation. In an abstract class some methods can be concrete. In an
interface class, no accessibility modifiers are allowed. An abstract
class may have accessibility modifiers.
11. What is the difference between a Struct and a Class?
Structs are value-type variables and are thus saved on the stack, additional overhead but faster retrieval. Another difference is that structs cannot inherit.
Structs are value-type variables and are thus saved on the stack, additional overhead but faster retrieval. Another difference is that structs cannot inherit.
Method and Property Questions
1. What’s the implicit name of the parameter that gets passed into the set method/property of a class? Value. The data type of the value parameter is defined by whatever data type the property is declared as.
2. What does the keyword “virtual” declare for a method or property? The method or property can be overridden.
3. How is method overriding different from method overloading? When
overriding a method, you change the behavior of the method for the
derived class. Overloading a method simply involves having another
method with the same name within the class that takes in different
variables.
4. Can you declare an override method to be static if the original method is not static? No. The signature of the virtual method must remain the same. (Note: Only the keyword virtual is changed to keyword override)
5. What are the different ways a method can be overloaded? Different parameter data types, different number of parameters, different order of parameters.
6. If
a base class has a number of overloaded constructors, and an inheriting
class has a number of overloaded constructors; can you enforce a call
from an inherited constructor to a specific base constructor? Yes,
just place a colon, and then keyword base (parameter list to invoke the
appropriate constructor) in the overloaded constructor definition
inside the inherited class.
Events and Delegates
1. What’s a delegate? A delegate object encapsulates a reference to a method.
2. What’s a multicast delegate? A delegate that has multiple handlers assigned to it. Each assigned handler (method) is called.
XML Documentation Questions
1. Is XML case-sensitive? Yes.
2. What’s the difference between // comments, /* */ comments and /// comments? Single-line comments, multi-line comments, and XML documentation comments.
3. How do you generate documentation from the C# file commented properly with a command-line compiler? Compile it with the /doc switch.
Debugging and Testing Questions
1. What debugging tools come with the .NET SDK?
1. CorDBG – command-line debugger. To use CorDbg, you must compile the original C# file using the /debug switch.
2. DbgCLR – graphic debugger. Visual Studio .NET uses the DbgCLR.
1. CorDBG – command-line debugger. To use CorDbg, you must compile the original C# file using the /debug switch.
2. DbgCLR – graphic debugger. Visual Studio .NET uses the DbgCLR.
2. What does assert() method do? In
debug compilation, assert takes in a Boolean condition as a parameter,
and shows the error dialog if the condition is false. The program
proceeds without any interruption if the condition is true.
3. What’s the difference between the Debug class and Trace class? Documentation looks the same. Use Debug class for debug builds, use Trace class for both debug and release builds.
4. Why are there five tracing levels in System.Diagnostics.TraceSwitcher? The
tracing dumps can be quite verbose. For applications that are
constantly running you run the risk of overloading the machine and the
hard drive. Five levels range from None to Verbose, allowing you to
fine-tune the tracing activities.
5. Where is the output of TextWriterTraceListener redirected?
To the Console or a text file depending on the parameter passed to the constructor.
To the Console or a text file depending on the parameter passed to the constructor.
6. How do you debug an ASP.NET Web application?
Attach the aspnet_wp.exe process to the DbgClr debugger.
Attach the aspnet_wp.exe process to the DbgClr debugger.
7. What are three test cases you should go through in unit testing? 1. Positive test cases (correct data, correct output).
2. Negative test cases (broken or missing data, proper handling).
3. Exception test cases (exceptions are thrown and caught properly).
2. Negative test cases (broken or missing data, proper handling).
3. Exception test cases (exceptions are thrown and caught properly).
8. Can you change the value of a variable while debugging a C# application? Yes. If you are debugging via Visual Studio.NET, just go to immediate window.
ADO.NET and Database Questions
1. What is the role of the DataReader class in ADO.NET connections?
It
returns a read-only, forward-only rowset from the data source. A
DataReader provides fast access when a forward-only sequential read is
needed.
2. 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. OLE-DB.NET is a
.NET layer on top of the OLE layer, so it’s not as fastest and
efficient as SqlServer.NET.
3. What is the wildcard character in SQL? Let’s
say you want to query database with LIKE for all employees whose name
starts with La. The wildcard character is %, the proper query with LIKE
would involve ‘La%’.
4. Explain ACID rule of thumb for transactions. A transaction must be:
1. Atomic - it is one unit of work and does not dependent on previous and following transactions.
2. Consistent - data is either committed or roll back, no “in-between” case where something has been updated and something hasn’t.
3. Isolated - no transaction sees the intermediate results of the current transaction).
4. Durable - the values persist if the data had been committed even if the system crashes right after.
1. Atomic - it is one unit of work and does not dependent on previous and following transactions.
2. Consistent - data is either committed or roll back, no “in-between” case where something has been updated and something hasn’t.
3. Isolated - no transaction sees the intermediate results of the current transaction).
4. Durable - the values persist if the data had been committed even if the system crashes right after.
5. What connections does Microsoft SQL Server support? Windows Authentication (via Active Directory) and SQL Server authentication (via Microsoft SQL Server username and password).
6. Between Windows Authentication and SQL Server Authentication, 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.
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.
7. What does the Initial Catalog parameter define in the connection string?
The database name to connect to.
The database name to connect to.
8. What does the Dispose method do with the connection object? Deletes it from the memory.
To Do: answer better. The current answer is not entirely correct.
To Do: answer better. The current answer is not entirely correct.
9. What is a pre-requisite for connection pooling?
Multiple processes must agree that they will share the same connection, where every parameter is the same, including the security settings. The connection string must be identical.
Multiple processes must agree that they will share the same connection, where every parameter is the same, including the security settings. The connection string must be identical.
Webservice Questions
1) What is WSDL WSDL is the Web Service Description Language, and it is implemented as a specific XML vocabulary. While it's very much more complex than what can be described here, there are two important aspects to WSDL with which you should be aware. First, WSDL provides instructions to consumers of Web Services to describe the layout and contents of the SOAP packets the Web Service intends to issue. It's an interface description document, of sorts. And second, it isn't intended that you read and interpret the WSDL. Rather, WSDL should be processed by machine, typically to generate proxy source code (.NET) or create dynamic proxies on the fly (the SOAP Toolkit or Web Service Behavior).2.What is a Windows Service and how does its lifecycle differ from a "standard" EXE?
Windows service is a application that runs in the background. It is equivalent to a NT service. The executable created is not a Windows application, and hence you can't just click and run it . it needs to be installed as a service, VB.Net has a facility where we can add an installer to our program and then use a utility to install the service. Where as this is not the case with standard exe
2) Can you give an example of when it would be appropriate to use a web service as opposed to non-serviced .NET component
Web service is one of main component in Service Oriented Architecture. You could use web services when your clients and servers are running on different networks and also different platforms. This provides a loosely coupled system. And also if the client is behind the firewall it would be easy to use web service since it runs on port 80 (by default) instead of having some thing else in Service Oriented Architecture applications.
3) What is the standard you use to wrap up a call to a Web service "SOAP."
5) What is the transport protocol you use to call a Web service SOAP HTTP with SOAP
5) What does WSDL stand for? "WSDL stands for Web Services Dsescription Langauge. There is WSDL.exe that creates a .wsdl Files which defines how an XML Web service behaves and instructs clients as to how to interact with the service.
eg: wsdl http://LocalHost/WebServiceName.asmx"
True or False: To test a Web service you must create a windows application or Web application to consume this service?
False.
6.What are the various ways of accessing a web service ?
1.Asynchronous Call
Application can make a call to the Webservice and then continue todo watever oit wants to do.When the service is ready it will notify the application.Application can use BEGIN and END method to make asynchronous call to the webmethod.We can use either a WaitHandle or a Delegate object when making asynchronous call.
The WaitHandle class share resources between several objects. It provides several methods which will wait for the resources to become available
The easiest and most powerful way to to implement an asynchronous call is using a delegate object. A delegate object wraps up a callback function. The idea is to pass a method in the invocation of the web method. When the webmethod has finished it will call this callback function to process the result
2.Synchronous Call
Application has to wait until execution has completed.
8)What are VSDISCO files?
VSDISCO files are DISCO files that support dynamic discovery of Web services. If you place the following VSDISCO file in a directory on your Web server, for example, it returns references to all ASMX and DISCO files in the host directory and any subdirectories not noted in elements:
xmlns="urn:schemas-dynamicdiscovery:disco.2000-03-17">
9)How does dynamic discovery work?
ASP.NET maps the file name extension VSDISCO to an HTTP handler that scans the host directory and subdirectories for ASMX and DISCO files and returns a dynamically generated DISCO document. A client who requests a VSDISCO file gets back what appears to be a static DISCO document.
Note that VSDISCO files are disabled in the release version of ASP.NET. You can reenable them by uncommenting the line in the section of Machine.config that maps *.vsdisco to System.Web.Services.Discovery.DiscoveryRequestHandler and granting the ASPNET user account permission to read the IIS metabase. However, Microsoft is actively discouraging the use of VSDISCO files because they could represent a threat to Web server security.
Assembly Questions
1. How is 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.
2. What are the ways to deploy an assembly? An MSI installer, a CAB archive, and XCOPY command.
3. What is 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.
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.
4. What namespaces are necessary to create a localized application? System.Globalization and System.Resources.
5. What is the smallest unit of execution in .NET?
an Assembly.
an Assembly.
6. When should you call the garbage collector in .NET?
As a good rule, you should not call the garbage collector. However, you could call the garbage collector when you are done using a large object (or set of objects) to force the garbage collector to dispose of those very large objects from memory. However, this is usually not a good practice.
As a good rule, you should not call the garbage collector. However, you could call the garbage collector when you are done using a large object (or set of objects) to force the garbage collector to dispose of those very large objects from memory. However, this is usually not a good practice.
7. How do you convert a value-type to a reference-type?
Use Boxing.
Use Boxing.
8. What happens in memory when you Box and Unbox a value-type?
Boxing converts a value-type to a reference-type, thus storing the object on the heap. Unboxing converts a reference-type to a value-type, thus storing the value on the stack.
Boxing converts a value-type to a reference-type, thus storing the object on the heap. Unboxing converts a reference-type to a value-type, thus storing the value on the stack.
General Questions
- What type of code (server or client) is found in a Code-Behind class?
- Server side this is a bit silly of a question but I was so you get it.
- Should validation (did the user enter a real date) occur server-side or client-side? Why?
- Client side and the server side. You should always check you data.
- What does the "EnableViewState" property do? Why would I want it on or off?
- Gets or sets a value indicating whether the server control persists its view state, and the view state of any child controls it contains, to the requesting client
- What is the difference between Server.Transfer and Respose.Redirect? Why would I choose one over the other?
- Server.
Transfer will prevent round trip. it will redirect pages which or in
the same directory. NO way to pass the query strings . Thru http context
we can able to get the previous page control values.
- Response.Redirect : There is a round trip to process the request. We can redirect to any page external internal other than aspx. We can pass the query string thru which we can manage sessions.
- Server.
Transfer will prevent round trip. it will redirect pages which or in
the same directory. NO way to pass the query strings . Thru http context
we can able to get the previous page control values.
- Can you explain the difference between an ADO.NET Dataset and anADO Recordset?
- DataSet is represented using XML so can travel safely over http and port 80 without concerns for a firewall etc. A recordset is an instance of a COM object and may not travel through firewalls
- For the same reason as stated in point 1 a dataset could be stored in a session variable of a web application without affecting the scalability while storing a recordset in a session variable would affect scalability.
- For a dataset XML is the internal representation as well as medium used for output but for a recordset XML is merely an output format.
- Dataset can hold several tables at once and also stores relationships and constraints on the tables. Recordset stores only the rows returned by the given query.
- Using dataset you can create a virtual representation of a database whose tables come from different data sources / RDBMSs. For example you could combine emp table from a SQL Server 2000 database with a dept table of Oracle and a salary table maintained using Excel in one dataset. Recordset is limited to results of one query on one database.
- Dataset is disconnected by its very architecture. Recordset can also work in disconnected mode.
- Both support batch updates
h. Both support filtering and sorting of data.
6. Can you give an example of what might be best suited to place in the Application_Start and Session_Start subroutines?
a. Application_start need for global variable which are available over the application.
Sesssion_Start : login dependent ( user dependent)
Sesssion_Start : login dependent ( user dependent)
7. If
I'm developing an application that must accommodate multiple security
levels though secure login and my ASP.NET web application is
spanned across three web-servers (using round-robin load balancing)
what would be the best approach to maintain login-in state for the
users?
spanned across three web-servers (using round-robin load balancing)
what would be the best approach to maintain login-in state for the
users?
a. Maintain
the login state security through a database. All the web server would
be maintaining the login state in the common database.
8. Can you explain what inheritance is and an example of when you might use it?
a. Inheritance
is desirable because you want to avoid writing the same code over and
over again. If you have two separate classes, and each one has to
implement a FirstName and LastName
property, you are going to have duplicate code. If you wish to change
the implementation of one of these properties, you need to find all
classes that have implemented these properties to make the changes. Not
only is this time-consuming, but you also increase the risk of
introducing bugs in the various classes.
9. Describe the difference between inline and code behind - which is best in a loosely coupled solution
a. inline
takes place in the html code. Clasic asp is in example of this. When
the server renders the page it spits out the html with whatever you told
it to do between the <%%>. The rendered page is then sent to the
user. The Code Behind is actions that take place on the server
10. Where would you use an iHTTPModule, and what are the limitations of any approach you might take in implementing one
a. Preprocessing before going to IIS.
11. What are the / benefits of View State
a. Easy to implement
b. •No server resources are required
c. •Enhanced security features ,like it can be encoded and compressed.
12. What are the disadvantages of view state?
a. Its large to transfer
b. It can be hacked
13. How is view state stored
a. View
State stored the value of page controls as a string which is hashed and
encoded in some hashing and encoding technology. It only contains
information about page and its controls. Its does not have any
interaction with server. View State uses
Hidden
field to store its information in a encoding format.
14. Describe session handling in a webfarm, how does it work and what are the limits
a. Using SQL server or any other database for storing sessions regarding current logged in user.
b. Using
State Server as one dedicated server for managing sessions. State
Server will run as service on web server having dotnet installed.
c. You can also make your load balance use sticky sessions but this can cause heavy load on certain servers and is not recommended.
15. Whats MSIL, and why should my developers need an appreciation of it if at all?
Microsoft Intermeidate lanaguage. which is the out put for all the .net supported languages after comiplation will produce.
Microsoft Intermeidate lanaguage. which is the out put for all the .net supported languages after comiplation will produce.
a. Appreciation for cross language support.
16. In what order do the events of an ASPX page execute. As a developer is it important to understand these events?
Stage
|
Description
| ||
Page request
|
The
page request occurs before the page life cycle begins. When the page is
requested by a user, ASP.NET determines whether the page needs to be
parsed and compiled (therefore beginning the life of a page), or whether
a cached version of the page can be sent in response without running
the page.
| ||
Start
|
In the start step, page properties such as Request and Response are set. At this stage, the page also determines whether the request is a postback or a new request and sets the IsPostBack property. Additionally, during the start step, the page's UICulture property is set.
| ||
Page initialization
|
During page initialization, controls on the page are available and each control's UniqueID
property is set. Any themes are also applied to the page. If the
current request is a postback, the postback data has not yet been loaded
and control property values have not been restored to the values from
view state.
| ||
Load
|
During
load, if the current request is a postback, control properties are
loaded with information recovered from view state and control state.
| ||
Validation
| |||
Postback event handling
|
If the request is a postback, any event handlers are called.
| ||
Rendering
|
Before rendering, view state is saved for the page and all controls. During the rendering phase, the page calls the Render method for each control, providing a text writer that writes its output to the OutputStream of the page's Response property.
| ||
Unload
| |||
1. Which met hod do you invoke on the DataAdapter control to load your generated dataset with data?
2. Fill()
12. Can you edit data in the Repeater control?
1. NO but you can make logical decisions with enabling you to chose which data to show.
13. Which template must you provide, in order to display data in a Repeater control?
1. ITemtemplate
14. . How can you provide an alternating color scheme in a Repeatercontrol?
1. lternateItemTemplate
15. What
property must you set, and what method must you call in your code, in
order to bind the data from some data source to the Repeatercontrol?
1. Datasource,
DataBind
DataBind
16. What base class do all Web Forms inherit from?
1. System.Web.UI.Page
17. What method do you use to explicitly kill a user s session?
1. abondon()
18. hich two properties are on every validation control?
1. control to validate, error message
19. What tags do you need to add within the asp:datagrid tags to bind
columns manually?
columns manually?
1. autogenerated columns is set to false
20. How do you create a permanent cookie?
1. <%
2. Response.Cookies("username") = "you"
3. Response.Cookies("username").Expires = Date.MaxValue
4. %>
21. What tag do you use to add a hyperlink column to the DataGrid?
1. hyper link column
22. Which method do you use to redirect the user to another page without performing a round trip to the client?
1. server.transfer
23. What is the transport protocol you use to call a Web service SOAP
http
http
24. what property do you have to set to tell the grid which page to go to when using the Pager object?
1. Page Index.
25. What tags do you need to add within the asp:datagrid tags to bind columns manually.
1. Autogenerate columns
26. Which property on a Combo Box do you set with a column name, prior to setting the DataSource, to display data in the combo box?
1. datatext
2. datavalue
27. How is a class property designated as read-only?
1. get
28. Which control would you use if you needed to make sure the values in two different controls matched?
1. compare filed validator
29. How many classes can a single .NET DLL contain?
1. as many as u want..
SQL Questions
1) what is a a DEADLOCKA condition that occurs when two processes are each waiting for the other to complete before proceeding. The result is that both processes hang. Deadlocks occur most commonly in multitasking and client/server environments. Ideally, the programs that are deadlocked, or the operating system, should resolve the deadlock, but this doesn't always happen.
The deadlock situation in the above code can be modeled like this.
2) what is a LIVELOCK
A condition that occurs when two or more processes continually change their state in response to changes in the other processes. The result is that none of the processes will complete. An analogy is when two people meet in a hallway and each tries to step around the other but they end up swaying from side to side getting in each other's way as they try to get out of the way.
No comments:
Post a Comment