Anda di halaman 1dari 22

To create a derived class in C#, the class declaration should be done as:

class child: parent

To create a derived class in VB.NET, the class declaration should be done as:

Class child
Inherits parent
End Class

Multiple inheritance

Multiple inheritance is the possibility that a child class can have multiple parents.
Human beings have always two parents, so a child will have characteristics from both
parents.

In OOP, multiple inheritance might become difficult to handle because it allows


ambiguity for the compiler. There are programming languages such as C++ that
allow multiple inheritance; however, other programming languages such as Java and
the .NET Framework languages do not allow multiple inheritance. Multiple inheritance
can be emulated in .NET using Multiple Interface Inheritance, which I will explain in
Part 3 of this series.

Sealed class

A sealed class is a class that does not allow inheritance. Some object model designs
need to allow the creation of new instances but not inheritance, if this is the case,
the class should be declared as sealed.

To create a sealed class in C#, the class declaration should be done as:

sealed class Shape

To create a sealed class in VB.NET, the class declaration should be done as:

NonInheritable Class Shape

Abstraction

Abstraction is "the process of identifying common patterns that have systematic


variations; an abstraction represents the common pattern and provides a means for
specifying which variation to use" (Richard Gabriel).

An abstract class is a parent class that allows inheritance but can never be
instantiated. Abstract classes contain one or more abstract methods that do not have
implementation. Abstract classes allow specialization of inherited classes.

Figure 2 shows a Shape class, which is an abstract class. In the real world, you never
calculate the area or perimeter of a generic shape, you must know what kind of
geometric shape you have because each shape (eg. square, circle, rectangle, etc.)
has its own area and perimeter formulas. The parent class shape forces all derived
classes to define the behavior for CalculateArea() and CalculatePerimeter(). Another
great example is a bank account. People own savings accounts, checking accounts,
credit accounts, investment accounts, but not generic bank accounts. In this case, a
bank account can be an abstract class and all the other specialized bank accounts
inherit from bank account.

To create an abstract class in C#, the class declaration should be done as:

abstract class Shape

To create an abstract class in VB.NET, the class declaration should be done as:

MustInherit Class Shape

To following code shows a sample implementation of an abstract class:

/// C#
--------------------------------------------------------------------------------
using System;
namespace DotNetTreats.OOSE.OOPSamples{
public abstract class Shape{
private float _area;
private System.Drawing.Color _color;
private float _perimeter;
public float Area{
get{
return _area;
}
set{
_area = value;
}
}

public System.Drawing.Color Color{


get{
return _color;
}
set{
_color = value;
}
}

public float Perimeter{


get{
return _perimeter;
}
set{
_perimeter = value;
}
}

public abstract void CalculateArea();

public abstract void CalculatePerimeter();

}
}

Listing 1. The Shape abstract class in C#.

Polymorphism

Polymorphism allows objects to be represented in multiple forms. Even though


classes are derived or inherited from the same parent class, each derived class will
have its own behavior. Polymorphism is a concept linked to inheritance and assures
that derived classes have the same functions even though each derived class
performs different operations.

Figure 2 shows a Rectangle, a Circle, and Square. All of them are shapes and as
shapes their area and perimeter can be calculated; however, each shape calculates
its area in a specialized way. Declaring a member as abstract allows polymorphism.
The Shape class defines the CalculateArea() and CalculatePerimeter() methods as
abstract, this allows each derived class to override the implementation of the
parent's methods.

To following sample code shows an implementation of a derived class (rectangle).


The specific CalculateArea() and CalculatePerimeter() methods for the rectangle class
illustrate polymorphism:

/// C#
--------------------------------------------------------------------------------
using System;
namespace DotNetTreats.OOSE.OOPSamples{
class Rectangle : Shape{
private float _height;
private float _width;
public rectangle(float height, float width){
_height = height;
_width = width;
}
public float Height{
get{
return _height;
}
set{
_height = value;
}
}
public float Width{
get{
return _width;
}
set{
_width = value;
}
}
public override void CalculateArea(){
this.Area = _height * _width;
}
public override void CalculatePerimeter(){
this.Perimeter = (_height * 2) + (_width * 2);
}
}
}

Listing 2. Polymorphism represented in the Rectangle's methods.

Virtual keyword

The virtual keyword allows polymorphism too. A virtual property or method has an
implementation in the base class, and can be overriden in the derived classes.

To create a virtual member in C#, use the virtual keyword:

public virtual void Draw()

To create a virtual member in VB.NET, use the Overridable keyword:

Public Overridable Function Draw()

Override keyword

Overriding is the action of modifying or replacing the implementation of the parent


class with a new one. Parent classes with virtual or abstract members allow derived
classes to override them.

To override a member in C#, use the override keyword:

public override void CalculateArea()

To override a member in VB.NET, use the Overrides keyword:

Public Overrides Function CalculateArea()

Conclusion

Inheritance allows developers to manage a generalization and specialization


relationship between objects. OOP concepts such as abstraction and polymorphism
help to define better object models where object hierarchies are designed with
reusability in mind. In this article, I examined the concept of inheritance, abstraction,
and polymorphism. The third and last part of this series will examine the concepts of
interface, multiple interface inheritance, collections, and overloading.

ASP.NET Interview Questions

This is a list of questions I have gathered and created over a


period of time from my experience, many of which I felt where
incomplete or simply wrong. I have finally taken the time to
go through each question and correct them to the best of my
ability. However, please feel free to post feedback to
challenge, improve, or suggest new questions. I want to
thank those of you that have contributed quality questions and
corrections thus far.

There are some questions in this list that I do not consider to


be good questions for an interview. However, they do exist on
other lists available on the Internet so I felt compelled to keep
them here for easy access.

1. Describe the role of inetinfo.exe, aspnet_isapi.dll


andaspnet_wp.exe in the page loading process.
inetinfo.exe is theMicrosoft IIS server running,
handling ASP.NET requests among other things.When
an ASP.NET request is received (usually a file with
.aspx extension), the ISAPI filter aspnet_isapi.dll takes
care of it by passing the request tothe actual worker
process aspnet_wp.exe.

2. What’s the difference between Response.Write()


andResponse.Output.Write()?
Response.Output.Write() allows you to write formatted
output.

3. What methods are fired during the page load?


Init() - when the page is instantiated
Load() - when the page is loaded into server memory
PreRender() - the brief moment before the page is
displayed to the user as HTML
Unload() - when page finishes loading.

4. When during the page processing cycle


is ViewState available?
After the Init() and before the Page_Load(), or
OnLoad() for a control.

5. What namespace does the Web page belong in


the .NET Framework class hierarchy?
System.Web.UI.Page

6. Where do you store the information about the


user’s locale?
System.Web.UI.Page.Culture
7. What’s the difference between
Codebehind="MyCode.aspx.cs"
andSrc="MyCode.aspx.cs"?
CodeBehind is relevant to Visual Studio.NET only.

8. What’s a bubbled event?


When you have a complex control, like DataGrid,
writing an event processing routine for each object
(cell, button, row, etc.) is quite tedious. The controls
can bubble up their eventhandlers, allowing the main
DataGrid event handler to take care of its
constituents.

9. Suppose you want a certain ASP.NET function


executed on MouseOver for a certain button.
Where do you add an event handler?
Add an OnMouseOver attribute to the button.
Example:
btnSubmit.Attributes.Add("onmouseover","someClient
CodeHere();");

10. What data types do the RangeValidator control


support?
Integer, String, and Date.

11. Explain the differences between Server-side and


Client-side code?
Server-side code executes on the server. Client-side
code executes in the client's browser.

12. What type of code (server or client) is found in a


Code-Behind class?
The answer is server-side code since code-behind is
executed on the server. However, during the code-
behind's execution on the server, it can render client-
side code such as JavaScript to be processed in the
clients browser. But just to be clear, code-behind
executes on the server, thus making it server-side
code.

13. Should user input data validation occur server-


side or client-side? Why?
All user input data validation should occur on the
server at a minimum. Additionally, client-side
validation can be performed where deemed
appropriate and feasable to provide a richer, more
responsive experience for the user.

14. What is the difference between Server.Transfer


and Response.Redirect? Why would I choose
one over the other?
Server.Transfer transfers page processing from one
page directly to the next page without making a
round-trip back to the client's browser. This provides a
faster response with a little less overhead on the
server. Server.Transfer does not update the clients url
history list or current url. Response.Redirect is used to
redirect the user's browser to another page or site.
This performas a trip back to the client where the
client's browser is redirected to the new page. The
user's browser history list is updated to reflect the new
address.

15. Can you explain the difference between an


ADO.NET Dataset and an ADO Recordset?
Valid answers are:
· A DataSet can represent an entire relational
database in memory, complete with tables, relations,
and views.
· A DataSet is designed to work without any
continuing connection to the original data source.
· Data in a DataSet is bulk-loaded, rather than being
loaded on demand.
· There's no concept of cursor types in a DataSet.
· DataSets have no current record pointer You can use
For Each loops to move through the data.
· You can store many edits in a DataSet, and write
them to the original data source in a single operation.
· Though the DataSet is universal, other objects in
ADO.NET come in different versions for different data
sources.

16. What is the Global.asax used for?


The Global.asax (including the Global.asax.cs file) is
used to implement application and session level
events.

17. What are the Application_Start and


Session_Start subroutines used for?
This is where you can set the specific variables for the
Application and Session objects.

18. Can you explain what inheritance is and an


example of when you might use it?
When you want to inherit (use the functionality of)
another class. Example: With a base class named
Employee, a Manager class could be derived from the
Employee base class.

19. Whats an assembly?


Assemblies are the building blocks of the .NET
framework. Overview of assemblies from MSDN

20. Describe the difference between inline and code


behind.
Inline code written along side the html in a page.
Code-behind is code written in a separate file and
referenced by the .aspx page.

21. Explain what a diffgram is, and a good use for


one?
The DiffGram is one of the two XML formats that you
can use to render DataSet object contents to XML. A
good use is reading database data to an XML file to be
sent to a Web Service.

22. Whats MSIL, and why should my developers


need an appreciation of it if at all?
MSIL is the Microsoft Intermediate Language. All .NET
compatible languages will get converted to MSIL.
MSIL also allows the .NET Framework to JIT compile
the assembly on the installed computer.

23. Which method do you invoke on the DataAdapter


control to load your generated dataset with
data?
The Fill() method.

24. Can you edit data in the Repeater control?


No, it just reads the information from its data source.

25. Which template must you provide, in order to


display data in a Repeater control?
ItemTemplate.

26. How can you provide an alternating color scheme


in a Repeater control?
Use the AlternatingItemTemplate.

27. What property must you set, and what method


must you call in your code, in order to bind the
data from a data source to the Repeater control?
You must set the DataSource property and call the
DataBind method.

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


The Page class.

29. Name two properties common in every validation


control?
ControlToValidate property and Text property.

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

31. Which control would you use if you needed to


make sure the values in two different controls
matched?
CompareValidator control.

32. How many classes can a single .NET DLL contain?


It can contain many classes.
Web Service Questions

1. What is the transport protocol you use to call a


Web service?
SOAP (Simple Object Access Protocol) is the preferred
protocol.

2. True or False: A Web service can only be written


in .NET?
False

3. What does WSDL stand for?


Web Services Description Language.

4. Where on the Internet would you look for Web


services?
http://www.uddi.org

5. True or False: To test a Web service you must


create a Windows application or Web application
to consume this service?
False, the web service comes with a test page and it
provides HTTP-GET method to test.

State Management Questions

1. What is ViewState?
ViewState allows the state of objects (serializable) to
be stored in a hidden field on the page. ViewState is
transported to the client and back to the server, and is
not stored on the server or any other external source.
ViewState is used the retain the state of server-side
objects between postabacks.

2. What is the lifespan for items stored in


ViewState?
Item stored in ViewState exist for the life of the
current page. This includes postbacks (to the same
page).

3. What does the "EnableViewState" property do?


Why would I want it on or off?
It allows the page to save the users input on a form
across postbacks. It saves the server-side values for a
given control into ViewState, which is stored as a
hidden value on the page before sending the page to
the clients browser. When the page is posted back to
the server the server control is recreated with the
state stored in viewstate.
4. What are the different types of Session state
management options available with ASP.NET?
ASP.NET provides In-Process and Out-of-Process state
management. In-Process stores the session in
memory on the web server. This requires the a
"sticky-server" (or no load-balancing) so that the user
is always reconnected to the same web server. Out-of-
Process Session state management stores data in an
external data source. The external data source may
be either a SQL Server or a State Server service. Out-
of-Process state management requires that all objects
stored in session are serializable.

ASP.NET Interview Questions

1. Describe the role of inetinfo.exe, aspnet_isapi.dll andaspnet_wp.exe in the page loading


process. inetinfo.exe is theMicrosoft IIS server running, handling ASP.NET requests among
other things.When an ASP.NET request is received (usually a file with .aspx extension),the
ISAPI filter aspnet_isapi.dll takes care of it by passing the request tothe actual worker process
aspnet_wp.exe.

2. What’s the difference between Response.Write() andResponse.Output.Write()? The latter


one allows you to write formattedoutput.

3. What methods are fired during the page load? Init() - when the pageis instantiated, Load()
- when the page is loaded into server memory,PreRender() - the brief moment before the page
is displayed to the user asHTML, Unload() - when page finishes loading.

4. Where does the Web page belong in the .NET Framework class
hierarchy?System.Web.UI.Page

5. Where do you store the information about the user’s locale? System.Web.UI.Page.Culture

6. What’s the difference between Codebehind="MyCode.aspx.cs" andSrc="MyCode.aspx.cs"?


CodeBehind is relevant to Visual Studio.NET only.

7. What’s a bubbled event? When you have a complex control, like DataGrid, writing an event
processing routine for each object (cell, button, row, etc.) is quite tedious. The controls can
bubble up their eventhandlers, allowing the main DataGrid event handler to take care of its
constituents.

8. Suppose you want a certain ASP.NET function executed on MouseOver overa certain button.
Where do you add an event handler? It’s the Attributesproperty, the Add function inside that
property. So btnSubmit.Attributes.Add("onMouseOver","someClientCode();")

9. What data type does the RangeValidator control support? Integer,String and Date.

10. Explain the differences between Server-side and Client-side code? Server-side code runs
on the server. Client-side code runs in the clients’ browser.

11. What type of code (server or client) is found in a Code-Behind class? Server-side code.

12. Should validation (did the user enter a real date) occur server-side or client-side? Why?
Client-side. This reduces an additional request to the server to validate the users input.
13. What does the "EnableViewState" property do? Why would I want it on or off? It enables
the viewstate on the page. It allows the page to save the users input on a form.

14. What is the difference between Server.Transfer and Response.Redirect? Why would I
choose one over the other? Server.Transfer is used to post a form to another page.
Response.Redirect is used to redirect the user to another page or site.

15. Can you explain the difference between an ADO.NET Dataset and an ADO Recordset?
· A DataSet can represent an entire relational database in memory, complete with tables,
relations, and views.
· A DataSet is designed to work without any continuing connection to the original data source.
· Data in a DataSet is bulk-loaded, rather than being loaded on demand.
· There's no concept of cursor types in a DataSet.
· DataSets have no current record pointer You can use For Each loops to move through the
data.
· You can store many edits in a DataSet, and write them to the original data source in a single
operation.
· Though the DataSet is universal, other objects in ADO.NET come in different versions for
different data sources.

16. Can you give an example of what might be best suited to place in the Application_Start
and Session_Start subroutines? This is where you can set the specific variables for the
Application and Session objects.

17. 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? Maintain the login state security through a database.

18. Can you explain what inheritance is and an example of when you might use it? When you
want to inherit (use the functionality of) another class. Base Class Employee. A Manager class
could be derived from the Employee base class.

19. Whats an assembly? Assemblies are the building blocks of the .NET framework. Overview
of assemblies from MSDN

20. Describe the difference between inline and code behind. Inline code written along side the
html in a page. Code-behind is code written in a separate file and referenced by the .aspx
page.

21. Explain what a diffgram is, and a good use for one? The DiffGram is one of the two XML
formats that you can use to render DataSet object contents to XML. For reading database data
to an XML file to be sent to a Web Service.

22. Whats MSIL, and why should my developers need an appreciation of it if at all? MSIL is the
Microsoft Intermediate Language. All .NET compatible languages will get converted to MSIL.
23. Which method do you invoke on the DataAdapter control to load your generated dataset
with data? The .Fill() method

24. Can you edit data in the Repeater control? No, it just reads the information from its data
source

25. Which template must you provide, in order to display data in a Repeater control?
ItemTemplate

26. How can you provide an alternating color scheme in a Repeater control? Use the
AlternatingItemTemplate

27. 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 Repeater control? You must set the DataSource
property and call the DataBind method.

28. What base class do all Web Forms inherit from? The Page class.

29. Name two properties common in every validation control? ControlToValidate property and
Text property.

30. What tags do you need to add within the asp:datagrid tags to bind columns manually? Set
AutoGenerateColumns Property to false on the datagrid tag

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

32. What is the transport protocol you use to call a Web service? SOAP is the preferred
protocol.

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

34. What does WSDL stand for? (Web Services Description Language)

35. Where on the Internet would you look for Web services? (http://www.uddi.org)

36. 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? DataTextField property

37. Which control would you use if you needed to make sure the values in two different
controls matched? CompareValidator Control

38. True or False: To test a Web service you must create a windows application or Web
application to consume this service? False, the webservice comes with a test page and it
provides HTTP-GET method to test.

39. How many classes can a single .NET DLL contain? It can contain many classes.
1) What is CLS (Common Language Specificaiton)?
It provides the set of specificaiton which has to be adhered by any new
language writer / Compiler writer for .NET Framework. This ensures
Interoperability. For example: Within a ASP.NET application written in C#.NET
language, we can refer to any DLL written in any other language supported by
.NET Framework. As of now .NET Supports around 32 languages.

2) What is CTS (Common Type System)?


It defines about how Objects should be declard, defined and used within .NET.
CLS is the subset of CTS.

3) What is Boxing and UnBoxing?


Boxing is implicit conversion of ValueTypes to Reference Types (Object) .
UnBoxing is explicit conversion of Reference Types (Object) to its equivalent
ValueTypes. It requires type-casting.

4) What is the difference between Value Types and Reference Types?


Value Types uses Stack to store the data where as the later uses the Heap to
store the data.

5) What are the different types of assemblies available and their purpose?
Private, Public/shared and Satellite Assemblies.

Private Assemblies : Assembly used within an application is known as private


assemblies

Public/shared Assemblies : Assembly which can be shared across applicaiton is


known as shared assemblies. Strong Name has to be created to create a
shared assembly. This can be done using SN.EXE. The same has to be
registered using GACUtil.exe (Global Assembly Cache).

Satellite Assemblies : These assemblies contain resource files pertaining to a


locale (Culture+Language). These assemblies are used in deploying an Gloabl
applicaiton for different languages.

6) Is String is Value Type or Reference Type in C#?


String is an object (Reference Type).
2) 1. Explain the differences between Server-side and Client-side code?
Server side code basically gets executed on the server (for example on a
webserver) per request/call basis, while client side code gets executed and
rendered on the client side (for example web browser as a platform) per
response basis.

2. What type of code (server or client) is found in a Code-Behind


class?
In the Code-behind class the server side code resides, and it generates the
responses to the client appropriately while it gets called or requested.

3. Should validation (did the user enter a real date) occur


server-side or client-side? Why?
That depends. In the up browsers (like IE 5.0 and up and Netscape 6.0) this
would help if it gets validated on the client side, because it reduces number of
round trips between client and server. But for the down level browsers (IE 4.0
and below and Netscape 5.0 and below) it has to be on server side. Reason
being the validation code requires some scripting on client side.

4. What does the "EnableViewState" property do? Why would I want it on or


off?
EnableViewState stores the current state of the page and the objects in it like
text boxes, buttons, tables etc. So this helps not losing the state between the
round trips between client and server. But this is a very expensive on browser.
It delays rendering on the browser, so you should enable it only for the
important fields/objects
5. What is the difference between Server.Transfer and
Response.Redirect? Why
would I choose one over the other?
Server.Transfer transfers the currnet context of the page to the next page and
also avoids double roundtrips. Where as Response.Redirect could only pass
querystring and also requires roundtrip.

6. Can you give an example of when it would be appropriate to use a


web service as opposed to a non-serviced .NET component
Webservice is one of main component in Service Oriented Architecture. You
could use webservices 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 webserivce
since it runs on port 80 (by default) instead of having some thing else in SOA
apps
.
7. Let's say I have an existing application written using Visual
Studio 6 (VB 6, InterDev 6) and this application utilizes Windows 2000
COM+ transaction services. How would you approach migrating this
application to .NET
You have to use System.EnterpriseServices namespace and also COMInterop
the existing application

8. Can you explain the difference between an ADO.NET Dataset and an


ADO Recordset?
ADO.NET DataSet is a mini RDBMS based on XML, where as RecordSet is
collection of rows. DataSet is independent of connection and communicates to
the database through DataAdapter, so it could be attached to any well defined
collections like hashtable, dictionary, tables, arraylists etc. practically. And also
it can be bound to DataGrid etc. controls straightaway. RecordSet on the
otherhand is tightly coupled to Database System.

9. Can you give an example of what might be best suited to place in


the Application_Start and Session_Start subroutines?
In the Application_Start event you could store the data, which is used
throughout the life time of an application for example application name, where
as Session_Start could be used to store the information, which is required for
that session of the application say for example user id or user name.

10. If I'm developing an application that must accomodate multiple


security levels though secure login and my ASP.NET web appplication is
spanned across three web-servers (using round-robbin load balancing)
what would be the best approach to maintain login-in state for the
users?
Use the state server or store the state in the database. This can be easily done
through simple setting change in the web.config.
<sessionState
mode="InProc"
stateConnectionString="tcpip=127.0.0.1:42424"
sqlConnectionString="data source=127.0.0.1;user id=sa;password="
cookieless="false"
timeout="30"
/>
in the above one instead of mode="InProc", you specifiy stateserver or
sqlserver.

11. What are ASP.NET Web Forms? How is this technology different than
what is available though ASP (1.0-3.0)?
ASP.NET webforms are analogous to Windows Forms which are available to
most VB developers. A webform is essentially a core container in a Page. An
empty webform is nothing but a HTML Form tag(control) running at server and
posting form to itself by default, but you could change it to post it to
something else. This is a container, and you could place the web controls, user
controls and HTML Controls in that one and interact with user on a postback
basis.

12. How does VB.NET/C# achieve polymorphism?


Polymorphism is achieved through virtual, overloaded, overridden methods in
C# and VB.NET
11. Can you explain what inheritance is and an example of when you
might use it?
.

13. How would you implement inheYou missed the number sequence here).
Inheritance is extending the properites, behaviour, methods to child classes
from super classes. VB.NET and C# provide single inheritance, means the
subclasses can be derived from only one parent unlike C++, where true
multiple inheritance is possible. As an alternate to implement multiple
inheritance, we could do the same to implement interfaces to the parent
classes and implement the same interfaces to derive the child classesritance
using VB.NET/C#?

14. Whats an assembly


An assembly is the primary building block of .NET. It's a reusable, self-
describing,
versionable deployment unit for types and resources. They are self-describing
so to allow the .NET runtime to fully understand the application and enforce
dependency and versioning rules

15. Describe the difference between inline and code behind - which is
best in a
16. loosely coupled solution
5 and 16. (You missed the sequence again). Inline style is mixing the server
side code and client side code (HTML and javascript) on the same page and
run it. Where as codebehind is seperating the server side in a different page
(enabling developers/coders to work) and leaving the client side code to do the
presentation only (so designers would work on it). Inline code would be
simplest way of approach because it doesn't require any pre-compilation. But
it is not good in many ways, i. You mix the presentation and server side code
together so whenever there is a change it would be tough to maintain. ii. The
event processing would be a night mare in inline code. iii. Since the
codebehind needs to be compile in advance, it would be faster unline inline,
which is interpreted per call basis. In a loosely couple situation, code-behind
would be the best way to approach. Because it provides better performance
3) 1. What does the keyword static mean when applied to a class member?
1. It means the method can be called through the class without instantiating
the class.

2. Declare a method called calculate that takes one integer, adds one and
returns the result. Allow this method to be overridden by an inheriting class.
2.
Public virtual int calculate(int value)
{
newValue = value + 1;
return newValue;
}
value++;
return value;

3. What is the difference between a class and a struct?


3. The class object is stored in the heap and struct object is stored in the
stack. Therefore accessing and removing data from the struct is faster than for
a class.

4. What is the difference between a class and an interface?

4. You can instantiate a class but you cannot instantiate an interace you can
only offer the functionality of that interface.

5. What are the .Net web authentication options and which one would
generally be used for a secured/public site?
5. None
Windows Authentication –Secured side
IIS Authentication
Forms Authentication – Public Side

6. What are some .Net options for maintaining session state?


6. In process and out of process. (wasn't sure about this one?)
I believe the 6th one could be
Querystring, Cookies, Session objects (variables)
I wasn't sure, but I knew they could either be handled in the memory on the
local machine (in process) or through the ASP.NET state service running either
locally or remotely (out of process).

7. What is a Singleton?
7. This ensures that a class can only be instantiated once.
4) CTS - The common type system is a rich type system, built into the common
language runtime, that supports the types and operations found in most
programming languages. The common type system supports the complete
implementation of a wide range of programming languages.

3. System.Diagnostics

4. System.Data.Common

5. System.Reflection

6.
Protected - Available only to classes that inherit from our class.
Friend - Available only to code within the project/component.
Protected Friend - Available only to classes that inherit from our class (in any
project) or to code within our project/component. This is a combination of
Protected and Friend.

7. Abstract classes cannot be instantiated they can only be extended. You call
the functionality of the abstract class without having to create an instance of
it.

8.
a) Interfaces don't have implementation and abstract classes can be partially
implemented.

From a practical point of view, interfaces can be implemented in any class and
more than one interface can be implemented in a class, but abstract classes
can only be implemented in the same class hierarchy (subclassing) and only
one abstract class can be implemented in a class.

b) Basically it's an mixture of non-virtual methods and method hiding. That is,
in VB.NET overriding methods never hide while non-overriding methods always
do.
c)
Overloading a method means that you are providing another version of an
existing method that takes different input arguments/parameters. The method
will have the same name as an existing method and may or may not have a
different return type. It must have a different number and/or type of input
parameters. Methods are identified by their name, and number and type of
arguments. This is known as the method's signature. The return value of a
method is not regarded as part of the signature. Overloading can be done
within the same class i.e. you can have several methods defined in one class
that have the same name, but different arguments, or it can be done in a class
related to another by inheritance i.e. the superclass contains one method, and
a subclass provides another version of the method with the same name and
different arguments.

Overriding a method means that you are replacing the method with your own
version. The overriding method must be defined identically to the method
being replaced. Overriding can only be done in inherited classes i.e. the
superclass provides a method and the subclass redefines the method with one
that has exactly the same name and arguments as the superclass version. This
will cause the method to behave differently when it is called by an object of
the subclass, to when it is called by an object of the superclass.

9.
Has application scope...variable only goes out of scope when the application
ends.
code:

public static int Size = 0;

10.
The datareader is a forward only, readonly object. It will keep a connection
open as long as it is open. It is a fast way to loop through records.

The dataset can be used like an in memory representation of the database.


You can use DataViews to filter and sort records for presentation. You can also
establish relationships with the dataRelation object. You can use the dataset
with a data adapter to update the database. These objects can keep track of
changes and original values. When updating the database these objects can
help to resolve conflicts or concurrency issues.
5) .1 What is serialization?
Serialization is the process of converting an object into a stream of bytes.
Deserialization is the opposite process, i.e. creating an object from a stream of
bytes. Serialization/Deserialization is mostly used to transport objects (e.g.
during remoting), or to persist objects (e.g. to a file or database).
6.2 Does the .NET Framework have in-built support for serialization?
There are two separate mechanisms provided by the .NET class library -
XmlSerializer and SoapFormatter/BinaryFormatter. Microsoft uses XmlSerializer
for Web Services, and SoapFormatter/BinaryFormatter for remoting. Both are
available for use in your own code.
6) Can .Net Components can be used from a COM?
Yes, can be used. But There are few restrictions such as COM needs an object
to be created. So static methods, parameterized constructor can not be used
from COM. These are used by COM using a COM Callable Wrapper (CCW).
TlbImp.exe and TlbExp.exe
How does .NET Remoting work?
It involves sending messages along channels. Two of the standard channels
are HTTP and TCP. TCP is for LANs only and HTTP can be used on LANs or
WANs (internet). TCP uses binary serialization and HTTP uses SOAP (.Net
Runtime Serialization SOAP Formatter).

There are 3 styles of remote access:


SingleCall: Each incoming request is handled by new instance.
Singleton: All requests are served by single server object.
Client-Activated Object: This is old state-full DCOM model. Where client
receives reference to the remote object and keep until it finished with it.
7) Object Oriented Programming:
It is a Style of programming that represents a program as a system of objects
and enables code-reuse.

Encapsulation:
Binding of attributes and behaviors. Hiding the implementation and exposing
the functionality.

Abstraction:
Hiding the complexity. Defining communication interface for the functionality
and hiding rest of the things.
In .Net destructor can not be abstract. Can define Either Finalize / Destructor.
For Destructor access specifiers can not be assigned. It is Private.

Overloading:
Adding a new method with the same name in same/derived class but with
different number/types of parameters. Implements Polymorphism.

Overriding:
When we need to provide different implementation than the provide by base
class, We define the same method with same signatures in the derived class.
Method must be Protected/Protected-Friend/Public for this purpose. (Base
class routine can be called by Mybase.Method, base.Method).

Shadowing:
When the method is defined as Final/sealed in base class and not overridable
and we need to provide different implementation for the same. We define
method with Shadows/new.

Inheritance:
Gives you ability to provide is-a relationship. Acquires attributes and behaviors
from another. When a class acquires attributes and behaviors from another
class. (must not be Final or sealed class in .Net)

Abstract Class:
Instance can not be created. Optionally can have one or more abstract
methods but not necessary. Can provide body to Classes.

Interface:
What a Class must do, But not how-to.
Bridge for the communication when the caller does not know to whom he is
calling.
Describes externally visible behavior of element.
Only Public members which defines the means of the communication with the
outer world. Can-be-Used-As Relationship.
Can not contain data but can declare property. There can be no
implementation. Interface can be derived from another interface.
Polymorphism:
Mean by more than one form. Ability to provide different implementation
based on different no./type of parameters. A method behaves differently based
on the different input parameters. Does not depend on the Return-Type.

Pure-Polymorphism:
Make an method abstract/virtual in base class. Override it in Derived Class.
Declare a variable of type base class and assign an object of derived class to
it. Now call the virtual/abstract method. The actual method to be called is
decided at runtime.

Early-Binding:
Calling an non-virtual method decides the method to call at compile time is
known as Early-Binding.

Late-Binding:
Same as pure-polymorphism.

Identifiers/Access Specifies and scope:


VB.NET: Private, Protected, Friend, Protected Friend, Public.
C#: private, protected, internal, protected internal, public.

What is a Delegate?
A strongly typed function pointer. A delegate object encapsulates a reference
to a method. When actual function needs to be called will be decided at run-
time.

Static Variable and Its Life-Time:


VB.NET: Public Shared VAR As Type.
C#: public static Type VAR;
Life time is till the class is in memory.

Constructor:
Special Method Always called whenever an instance of the class is created.

Destructor/Finalize:
Called by GC just before object is being reclaimed by GC.

ASP.Net
Different Types of Caching?
Output Caching: stores the responses from an asp.net page.
Fragment Caching: Only caches/stores the portion of page (User Control)
Data Caching: is Programmatic way to Cache objects for performance.

Authentication and Authorization:


Authentication is identifying/validating the user against the credentials
(username and password) and Authorization performs after authentication.
Authorization allowing access of specific resource to user.

Different Types of Directives:


Page, Register, Control, OutputCache, Import, Implements, Assembly,
Reference

Difference between Server-Side and Client-Side:


Server-Side code is executed on web-server and does not transmitted to
client, while client-side code executed on client(browser) and is rendered to
client along with the content.

Difference Server.Transfer and Response.Redirect:


Both ends the processing for the current request immediately. Server.Transfer
start executing the another resource specified as parameter without
acknowledgement to client(browser) while Response.Redirect intimate client
that your requested resource is available at this location and then client
request for that resource.

Different Types of Validators and Validation Controls:


RequiredFieldValidator, RangeValidator, RegularExpressionValidator,
CompareValidator, CustomValidator, ValidationSummary

How to Manage State in ASP.Net?


Client based: ViewState, QueryString and Cookies Server based: Session,
Application.

Difference between User Control and Custom Control:


CUSTOM Controls are compiled code (Dlls), easier to use, difficult to create,
and can be placed in toolbox. Drag and Drop controls. Attributes can be set
visually at design time. Can be used by Multiple Applications (If Shared Dlls),
Even if Private can copy to bin directory of webApp add reference and use.
Normally designed to provide common functionality independent of consuming
Application.

3 Types of Session State Modes?


InProc(cookieless, timeout),
StateServer (Server, Port stateConnectionString="tcpip=server:port"),
SQLServer (sqlconnectionstring) and Off.

What is ViewState and How it is managed, Its Advantages/Benefits?


ViewState is a special object that ASP.NET uses to maintain the state of page
and all webcontrols/ServerControls within it. It is in this object preserves the
states of various FORM elements during post-backs. It is rendered to
client(browser) as a Hidden variable __VIEWSTATE under <form>tag. We can
also add custom values to it.

What is web.config and machine.config:


machine.config is default configuration for all applications running under this
version, located in %WinDir%\Microsfot.Net\Framework\Version. Settings can
be overridden by Web.Config for an specific application Web.Config resides in
application’s root/virtual root and exists in sub-sequent folders.

Role of Global.asax:
Optional file contains the code to handle Application level events raised by
ASP.Net or By HttpModule. This file resides in application root directory.
Application_Start, _End, _AuthenticateRequest, _Error, Session_Start, _End,
BeginRequest, EndRequest. This file is parsed and compiled into dynamically
generated class derived from HttpApplication.

Page Life Cycle:


Init, LoadViewState, LoadPostBackData, Load,
RaisePostBackDataChangedEvent, RaisePostBackEvents, Pre-Render,
SaveViewState, Render, Unload, (IpostBackDataChangedEventHandler and
IpostBackEventHandler) Error, CommitTransaction, AbortTransaction, Abort
inetinfo.exe, aspnet_isapi.dll aspnet_wp.exe, HttpModules (OutputCache,
Session, Authentication, Authorization, Custom Modules Specified) and Then
HttpHandlers PageHandlerFactory for *.aspx

Can the action attribute of a server-side <form>tag be set to a value and if


not how can you possibly pass data from a form to a subsequent Page?
No assigning value will not work because will be overwritten at the time of
rendering. We can assign value to it by register a startup script which will set
the action value of form on client-side. Rest are Server.Transfer and
Response.Redirect.

ASP.Net List Controls and differentiate between them?


RadioButtonList, CheckBoxList, DropDownList, Repeater, DataGrid, DataList

Type Of Code in Code-Behind class:


Server-Side Code.

What might be best suited to place in the Application_Start and Session_Start:

Application level variables and settings initialization in App_Start


User specific variables and settings in Session_Start

Difference between inline and code-behind. Which is best?


Inline is mixed with html and code-behind is separated. Use code-behind,
Because Inline pages are loaded, parsed, compiled and processed at each first
request to page and remains in compiled code remains in cache until it
expires, If expires it again load, parse and compile While code-behind allows
to be pre-compiled and provide better performance.

Which Template must provide to display data in Repeater?


ItemTemplate.
8) How to Provide Alternating Color Scheme in Repeater?
AlternatingItemTemplate

What base class all Web Forms inherit from?


System.Web.UI.Page

What method do you use to explicitly kill a user’s Session?


HttpContext.Current.Session.Abandon()

How do you turn off cookies in one page of your asp.net application?
We will not use it. But can not turn off cookies from server. To allow or not is a
client side functionality.

Which two properties are on every validation control?


ControlToValidate and Text, ErrorMessage

How do you create a permanent cookie?


Set expires property to Date.MaxValue (HttpCookie.Expires = Date.MaxValue)

What is the standard you use to wrap up a call to a Web Service?


SOAP

Which method do you use to redirect to user to another page without


performing a round trip to Client?
Server.Transfer(“AnotherPage.aspx”)

What is transport protocol you use to call a Web-Service SOAP?


HTTP-POST

A Web Service can only be written in .NET?


FALSE

Where on internet would you look for Web services?


www.uddi.org
How many classes can a single .NET DLL contain?
Unlimited

How many namespaces are in .NET version 1.1?


124

What is a bubbled event?


When you have a complex control like DataGrid. Writing an event processing
routine for each object (cell, button, row etc.). DataGrid handles the events of
its constituents and will raise its own defined custom events.

Difference between ASP Session State and ASP.Net Session State?


ASP: relies on cookies, Serialize all requests from a client, Does not survive
process shutdown, Can not maintained across machines in a Web
farm/garden.

Layouts of ASP.NET Pages:


GridLayout and FlowLayout

Web User Control:


Combines existing Server and HTML controls by using VS.Net. to create
functional units that encapsulate some aspects of UI. Resides in Content Files,
which must be included in project in which the controls are used.

Composite Custom Control:


combination of existing HTML and Server Controls.

Rendered custom control:


create entirely new control by rendering HTML directly rather than using
composition.

Where do you store the information about user’s Locale?


Page.Culture

should Validation occur on Client/Server Side for Date Input?


Both. Client-side reduces extra round-trip. Server-Side ensures prevention
against hacking and failure against automated requests.

HTTP GET and HTTP POST:


As their names imply, both HTTP GET and HTTP POST use HTTP as their
underlying protocol. Both of these methods encode request parameters as
name/value pairs in the HTTP request. The GET method creates a query string
and appends it to the script's URL on the server that handles the request. For
the POST method, the name/value pairs are passed in the body of the HTTP
request message.

Anda mungkin juga menyukai