Properties of C#.Net Interview Questions(16)
1.Define Properties?
A) Properties are named members of classes,
structs, and interfaces. They provide a flexible mechanism to read, write, or
compute the values of private fields through accessors.
2.Define Accessors?
A) The accessor of a property contains the
executable statements associated with getting (reading or computing) or setting
(writing) the property. The accessor declarations can contain a get accessor, a
set accessor, or both.
3.Is properties store
the data?
A)Properties never store
the data just properties are used to transfer the data.
4.What is Set Accessor?
A) Set Accessor is used
to write the data into the data field.This will contain a default and fixed
variable named as “value”.Whenever we call the property to write the data,any
data we supply will come and store in value variable by default.
Syntax:
Set
{
DataFielfName=value;
}
5.What is Get Accessor?
A) Get Accessor is used
to read the data from the data field.Get accessor can’t write the data.
Syntax:
get
{
Return DataFielfName;
}
6.List the types of
properties?
A)C#.Net supports three
types of properties.They are:
Ø Read only Property
Ø Write only Property
Ø Read Write Property
7.Define Read only
Property?
A)This property is used
to read the data from the data field.We
can’t write the data into data field using this property.This property will
contain only one accessor i.e get accessor.
8.Define Write only
Property?
A)This property is used
to write the data into the data field of
a class.We can’t read the data from the data field using this property.This
property will contain only one accessor i.e set accessor.
9. Define Read Write
Property?
A)This property is used
to read the data from the data field and
to write the data in to the data field.This property will contain only two
accessors i.e get and set.
10.What is Interface
Properties?
A)When a properties can
be declared on interfaces then that is called as Interface properties. The accessor of an interface property does not
have a body.
11.Define Value?
A) The implicit parameter value is used in setting
accessors and to add or remove event handlers.
12. What are the advantages of properties in C#?
A)Following are the
advantages of properties. They are:
Ø Properties can validate data before allowing a
change.
Ø Properties can transparently expose data on a
class where that data is actually retrieved from some other source such a take
as a database.
Ø Properties can action when data is changed, such
as raising an event or changing the value of other fields.
13.Define static
property?
A)A property that is
preceded with a static keyword is known as static property.Static property can
access with the class name directly without instantiaon.
14.What is virtual property?
A) A property that is
preceded with a virtual keyword is known as virtual property.Virtual property
are used to override at derived class.
15. Can we use virtual, override or abstract
keywords on an accessor of a static property?
A)No, it is a compile
time error to use a virtual, abstract or override keywords on an accessor of a
static property.
16.Define Abstract
property?
A) A property that is
preceded with a abstract keyword is known as abstract property.Abstract
property should not have implementation in the class.
0 comments:
Post a Comment