C Sharp Rapid Fire Questions 2

Back to Notes on .NET

C# General Interview Questions

C# Questions on properties, events etc

C# Questions on Properties, Events etc

C# Rapid Fire Questions 1

C# Rapid Fire Questions 2

SQL Interview Questions 1

SQL Interview Questions 2














































More Questions...

16. Can you explain what inheritance is and an example
of when you might use it?

Ans. Inheriting a trait from a parent class!
Use the existing functionality along with its own

17. How would you implement inheritance using VB.NET/C#?
Ans. Derived Class : Baseclass
VB.NEt : Derived Class Inherits Baseclass

18. Whats an assembly ?
A Basic unit of executable code. 

  * It contains : Manifest - Meta data
  * versioning , Culture , IL, Reference

19. Describe the difference between inline and code behind.

Ans. Inline function bind at compile time can write in aspx page with in <% %> .

The code-behind is in a CS or a VB file.

20. Explain what a diffgram is, and a good use for one.
A DiffGram is an XML format that is used to identify
current and original versions of data elements. The DataSet uses the DiffGram format to load and persist its contents, and to serialize its contents for transport across a network connection. When a DataSet is written as a DiffGram, it populates the DiffGram with all the necessary information to accurately recreate the contents, though not the schema, of the DataSet, including column values from both the Original and Current row versions, row error information, and row order. When sending and retrieving a DataSet from an XML Web service, the DiffGram format is implicitly used.
Additionally, when loading the contents of a DataSet from
XML using the ReadXml method, or when writing the
contents of a DataSet in XML using the WriteXml method,
you can select that the contents be read or written as a

DiffGram Format
The DiffGram format is divided into three sections: the
current data, the original (or "before") data, and an
errors section, as shown in the following example.

<?xml version="1.0"?>



The DiffGram format consists of the following blocks of data:

The name of this element, DataInstance, is used for
explanation purposes in this documentation. A DataInstance
element represents a DataSet or a row of a DataTable.
Instead of DataInstance, the element would contain the name
of the DataSet or DataTable. This block of the DiffGram format contains the current data, whether it has been modified or not.
An element, or row, that has been modified is identified with
the diffgr:hasChanges annotation.

This block of the DiffGram format contains the original
version of a row. Elements in this block are matched to
elements in the DataInstance block using the diffgr:id
This block of the DiffGram format contains error information
for a particular row in the DataInstance block. Elements in
this block are matched to elements in the DataInstance block
using the diffgr:id annotation.

21. Where would you use an iHTTPModule, and what are

the limitations of any approach you might take in

implementing one?

Ans. It provides module initialization and disposal events

to the implementing class.



22. Compare Session State Vs. ViewState.
Session State is useful for storing values that must
be persisted across multiple pages by the same user. ViewState is useful for storing serializable data that must be
persisisted across PostBacks by a single page. If you use
Session State, the value you insert will remain in memory
until (1) The Session times out, or (2) Your code removes it.
If you use ViewState, the value you insert will remain in
ViewState until the user requests a different page.

ViewState stores data betwen PostBacks by putting it into a
hidden form field on the client HTML doc. when the doc is
Posted Back, the values are read from the hidden form field
and stored in memory until the page has finished processing.
 If ViewState is particularly large (and I'm talking KBs
here, not 6 bytes), it can negatively affect the speed at
which the HTML doc is downloaded by the browser.


24. Whats MSIL, and why should my developers need an appreciation of it if at all?
Ans. Microsoft Intermediate language. which is the out put
for all the .net supported languages after compilation will
produce. Appreciation is for cross language support.

Definition:Microsoft Intermediate Language (MSIL) is the
CPU-independent instruction set generated by .NET compilers
from .NET languages such as J#, C# or Visual Basic. MSIL is
compiled before or during execution of the program by a Virtual Execution System (VES), which is part of the Common Language Runtime module (CLR).

25. In what order do the events of an ASPX page execute. As a developer is it important to undertsand these events?

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.
 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.
 During load, if the current request is a postback, control
properties are loaded with information recovered from view
state and control state.
 During validation, the Validate method of all validator
controls is called, which sets the IsValid property of
individual validator controls and of the page.
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 is called after the page has been fully rendered, sent
to the client, and is ready to be discarded. At this point,

page properties such as Response and Request are unloaded and any cleanup is performed.

26. Which method do you invoke on the DataAdapter
control to load your generated dataset with data?


27. Can you edit data in the Repeater control?
Ans. NO


28. Which template must you provide, in order to display
data in a Repeater control?
Ans. ITemtemplate


29. How can you provide an alternating color scheme in a Repeatercontrol?
Ans. AlternateItemTemplate


30. 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?

Ans. Datasource, DataBind


31. What base class do all Web Forms inherit from?


32. What method do you use to explicitly kill a user's


33. How do you turn off cookies for one page in your site?


34. Which two properties are on every validation control?
Control to validate, Error message


35. What tags do you need to add within the
asp:datagrid tags to bind columns manually?
autogenerated columns is set to false


36. How do you create a permanent cookie?
Setting a permanent cookie is no harder than setting a
Session cookie. It’s very similar, except you give the cookie
an expiration date as well. It is very common that you don’t
specify any arbitrary expiration date, but instead expire the
cookie relative to the current date, using the DateAdd()
function, built into ASP. If you want to create a permanent
cookie called Name with a value of Nigel, which expires in one
month, you’d use the following code

Response.Cookies("Name") = "Nigel"
Response.Cookies("Name").Expires = DateAdd("m", 1, Now())


It’s that easy! Nothing more to it. You have now set a permanent cookie on your computer. Also, note that whenever the above code is called the expiration date of the cookie is renewed by one month from now.

There are a few more options which you can set, like for example the Path option. You can limit cookies to certain paths on your website, so you can set several cookies with the same name, as long as they belong to different paths. To do this, you would use the following code (extending the previous code):

Response.Cookies("Name").Path = "/foo/"

The above code would limit the cookie to the path foo. It is
also possible to assign multiple values to a particular cookie.
This is done using the so-called dictionary functionality of

a cookie. For example, if I’d want to store not only the first
name, but also the surname in my Name cookie, I’d be using
something like the following code:

Response.Cookies("Name")("First") = "Nigel"
Response.Cookies("Name")("Last") = "Pallett"
Response.Cookies("Name").Expires = DateAdd("m", 1, Now())


That’s all! Although there are a few more "advanced" options,
such as the Secure option and the Domain option, it is of no use now.

Retrieving Cookies

Retrieving the value of cookies is a very easy job, because
again everything is handled by the browser and your server.
All you have to use is ASP’s inbuilt functions.

There is no difference in retrieving a Session cookie or a
permanent cookie, and in both cases you use the following code:

Response.Write "Your Name: " & Request.Cookies("Name")


The above is for when you assigned only one value to a cookie. If you assigned multiple values you a cookie, you use the following code:

Response.Write "Your First Name: " & _
Response.Write "Your Surname: " & _


That’s all there is to it. It’s that easy, because everything
is done by your server and the ASP engine. Make sure you check out this handy function as well, which shows your visitors all the cookies they have stored.

Checking if Cookies are enabled

Before using cookies, it is often useful to check whether your
visitor accepts cookies. Some may disable it in their browser;

others may be using browsers that don’t support cookies at all (although very few browsers do). You should always keep the fact that your cookies might not work in the back of your mind, meaning, do NOT rely on cookies to work. If your website does not work when cookies are disabled, you must fix this.


37. What tag do you use to add a hyperlink column to
the DataGrid?

Ans.<asp:HyperLink id="some_Id_uDefine" runat="server">


38. What is the standard you use to wrap up a call to a
Web service?

Ans. SOAP - SOAP is a simple XML-based protocol to let
applications exchange information over HTTP.

SOAP (originally Simple Object Access Protocol) is a
protocol for exchanging XML-based messages over computer
network, normally using HTTP. SOAP forms the foundation
layer of the Web services stack, providing a basic messaging
framework that more abstract layers can build on. The original acronym was dropped with Version 1.2 of the standard, which became a W3C Recommendation on June 24, 2003, as it was
considered to be misleading.


There are several different types of messaging patterns in
SOAP, but by far the most common is the Remote Procedure Call (RPC) pattern, in which one network node (the client) sends a request message to another node (the server), and the server immediately sends a response message to the client. SOAP is the successor of XML-RPC, though it borrows its transport and interaction neutrality and the envelope/header/body from elsewhere, probably from WDDX [citation needed]. Originally designed by Dave Winer, Don Box, Bob Atkinson, and Mohsen Al-Ghosein in 1998 with backing from Microsoft (where Atkinson and Al-Ghosein worked at the time) as an object-access protocol, the SOAP specification is currently maintained by the XML Protocol Working Group of the World Wide Web Consortium.


39. Which method do you use to redirect the user to
another page without performing a round trip to the client?

Ans. Server.transfer


40. What is the transport protocol you use to call a
Web service 

SOAP. Transport Protocols: It is essential for the acceptance of Web Services that they are based on established Internet

infrastructure. This in fact imposes the usage of of the HTTP,
SMTP and FTP protocols based on the TCP/IP family of

transports. Messaging Protocol: The format of messages exchanged between Web Services clients and Web Services should be vendor neutral and should not carry details about the technology used to implement the service. Also, the message format should allow for extensions and different bindings to specific transport protocols. SOAP and ebXML Transport are specifications which fulfill these requirements. We expect that the W3C XML Protocol Working Group defines a successor standard.

41. True or False: A Web service can only be written
in .NET

42. What does WSDL stand for?
Webservice description language. WSDL is an XML format for describing network services as a set of endpoints
operating on messages containing either document-oriented or procedure-oriented information. The operations and messages are described abstractly, and then bound to a concrete network protocol and message format to define an endpoint. Related concrete endpoints are combined into abstract endpoints (services). WSDL is extensible to allow description of endpoints and their messages regardless of what message formats or network protocols are used to communicate, however, the only bindings described in this document describe how to use WSDL in conjunction with SOAP 1.1, HTTP GET/POST, and MIME.


43. What property do you have to set to tell the
grid which page to go to when using the Pager object?
Page Index.


44. Where on the Internet would you look for Web services?

45. What tags do you need to add within the
asp:datagrid tags to bind columns manually.

Ans. Autogenerate columns


46. 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?
Datatext, Datavalue

47. How is a property designated as read-only?


Public ReadOnly Property PropertyName As ReturnType
 Get   ‘Your Property Implementation goes in here
 End Get
End Property

In C#

public returntype PropertyName
  //property implementation goes here
 // Do not write the set implementation


48. Which control would you use if you needed to make sure the values in two different controls matched?
Ideally we would tend to use Comparefield validator.


49. True or False: To test a Web service you must create a windows application or Web application to consume this service?


50. How many classes can a single .NET DLL contain?
As many as u want!


51. Is ASP.NET a language?
No! Its a technology.
ASP.NET is not a platform independent language. As was
ASP.NET is more of a technology that provides a framework for building web applications. ASP.NET provides the reources needed to dynamically deliver html content (pages) to the end user. ASP.NET can leverage languages such as C#, VB.NET, and javascript to help provide a reliable, high perfofmance, and secure web application.