Académique Documents
Professionnel Documents
Culture Documents
Difference between
(i) Is and As
Ans:
The is operator in C# is used to check the object type and it returns a bool value: true if the object is the
same type and false if not.
Syntax:
The as operator does the same job of is operator but the difference is instead of bool, it returns
the object if they are compatible to that type, else it returns null.
Syntax:
Actually this affects the performance since each and every time the CLR will walk the inheritance hierarchy,
checking each base type against the specified type. To avoid this, use as it will do it in one step. Only for
checking the type should we use the is operator.
is equivalent to:
Connected Disconnected
It is connection It is dis_connection
oriented. oriented.
Datareader DataSet
Connected methods gives Disconnected get low in
faster performance speed and performance.
connected can hold the data disconnected can hold
of single table multiple tables of data
connected you need to use a disconnected you cannot
read only forward only data
reader
Data Reader can't Data Set can persist the
persist the data data
It is Read only, we We can update data
can't update the data.
C# Type System contains three Types , they are Value Types , Reference Types and
Pointer Types. C# allows us to convert a Value Type to a Reference Type, and back
again to Value Types . The operation of Converting a Value Type to a Reference Type
is called Boxing and the reverse operation is called Unboxing.
Boxing
1: int Val = 1;
2: Object Obj = Val; //Boxing
The first line we created a Value Type Val and assigned a value to Val. The second
line , we created an instance of Object Obj and assign the value of Val to Obj. From
the above operation (Object Obj = i ) we saw converting a value of a Value Type into
a value of a corresponding Reference Type . These types of operation is called Boxing.
UnBoxing
1: int Val = 1;
2: Object Obj = Val; //Boxing
3: int i = (int)Obj; //Unboxing
The first two line shows how to Box a Value Type . The next line (int i = (int) Obj)
shows extracts the Value Type from the Object . That is converting a value of a
Reference Type into a value of a Value Type. This operation is called UnBoxing.
Boxing and UnBoxing are computationally expensive processes. When a value type is
boxed, an entirely new object must be allocated and constructed , also the cast
required for UnBoxing is also expensive computationally.
b) Serialization
Working of serialization: The object is serialized to a stream, which carries not just
the data, but information about the object's type, such as its version, culture, and
assembly name. From that stream, it can be stored in a database, a file, or memory.
Serialization allows the developer to save the state of an object and recreate it as
needed, providing storage of objects as well as data exchange. Through
serialization, a developer can perform actions like sending the object to a remote
application by means of a Web Service, passing an object from one domain to
another, passing an object through a firewall as an XML string, or maintaining
security or user-specific information across applications.
c) MASTER PAGE
ASP.NET master pages allow you to create a consistent layout for the pages in your application.
A single master page defines the look and feel and standard behavior that you want for all of
the pages (or a group of pages) in your application. You can then create individual content
pages that contain the content you want to display. When users request the content pages,
they merge with the master page to produce output that combines the layout of the master
page with the content from the content page.
d) Constructor chaining
*********Do Not write the below link, just click on the link and write from internet*****
http://www.dotnetfunda.com/interviews/show/4054/w
hat-is-constructor-chaining
e) Validators
ASP.NET validation controls validate the user input data to ensure that useless, unauthenticated,
or contradictory data don't get stored.
RequiredFieldValidator
RangeValidator
CompareValidator
RegularExpressionValidator
CustomValidator
ValidationSummary
BaseValidator Class
The validation control classes are inherited from the BaseValidator class hence they inherit its
properties and methods. Therefore, it would help to take a look at the properties and the methods
of this base class, which are common for all the validation controls:
RequiredFieldValidator Control
The RequiredFieldValidator control ensures that the required field is not empty. It is generally tied
to a text box to force input into the text box.
RangeValidator Control
The RangeValidator control verifies that the input value falls within a predetermined range.
CompareValidator Control
The CompareValidator control compares a value in one control with a fixed value or a value in
another control.
RegularExpressionValidator
The RegularExpressionValidator allows validating the input text by matching against a pattern of
a regular expression. The regular expression is set in the ValidationExpression property.
The protected internal access specifier allows its members to be accessed in derived class,
containing class or classes within same application. However, this access specifier rarely used in
C# programming but it becomes important while implementing inheritance.