Dot Net 3
Dot Net 3
1. Dynamic Type
• The Dynamic Type performs the type checking of the dynamic type variable at
run time instead of compile time.
• Using the dynamic keyword, one can declare a dynamic type variable.
• Example: dynamic dyn=10;
2. Object Type:
• The object type enables user to assign value of any type to the variable of
object type.
• Object is an alias for the predefined System.
• Object class, type checking of the variable of object type is performed at
compile time.
• Example: Object x; X=15;
3. String Type:
• String type enables you to design string values to the variable of string type.
• The string type is an alias for the System.String class.
• It is an unchangeable sequence of Unicode characters contained within
double quotes.
Q5. Boxing and unboxing
• Boxing and Unboxing are important concepts used in the C# type systems
• They are used to create a link between the two major data types in C# that is
value type and reference type.
• All value types are stored in stack, but in some situations, they need to be
referenced as heap.
• As reference types are stored in heap; therefore, you can convert the value
type into reference type. This conversion is called as Boxing.
• Boxing is required in situations when a value type is converted into a base
object on an interface. The Common Language Runtime (CLR) converts the
value type to reference type.
• CLR allocates memory on heap and then copies the value type instance to it.
• Unboxing is the process of converting an instance of object type or interface
back to value type. This is done explicitly by using unboxing.
Q6.Delegates
• delegate is a type that represents references to methods with a particular
parameter list and return type.
• When you instantiate a delegate, you can associate ts instance with any
method with a compatible signature and return type.
• C# delegates are similar to pointers to functions, in C or C++.
• A delegate is a reference type variable that holds the reference to a method.
The reference can be changed at runtime.
• Delegate is also used to declare an Event and an Anonymous Method
Q7.Method Overloading:
• Method overloading is a concept in which a method behaves according to the
number and types of parameters passes to it.
• In method overloading, user can define many methods with the same name
but different signatures.
• A method signature is the combination of the method's name along with the
number, type and order of the parameters.
• When user call overloaded methods, a compiler automatically determines
which method should be used according to the signature specified in the
method call.
• Method overloading is used when methods are required to perform similar
task but with different input parameters.
Q8. Method Overriding
• Method Overriding in C# is similar to the virtual function in C++.
• Method Overriding is a technique that allows the invoking of functions from
another class (base class) in the derived class.
• Creating a method in the derived class with the same signature as a method in
the base class is called as method overriding.
• In simple words, Overriding is a feature that allows a subclass or child class to
provide a specific implementation of a method that is already provided by one
of its super-classes or parent classes.
• Method overriding is one of the ways by which C# achieve Run Time
Polymorphism
Q10. Inheritance
• The most important reason to use OOP is to promote reusability of code and
eliminate the redundant code.
• To reduce redundancy, the object-oriented languages support Inheritance.
• Inheritance is the property through which a class derives properties from an
class.
• A class that inherits the properties of another class is called a child or derived
• whereas, the class from which the child class inherits properties is known a
parent or base class.
• C# supports single inheritance, hierarchical inheritance and multilevel
inheritance because there is only a single base class.
• It does not support multiple inheritances directly.
• To implement multiple inheritances, you need to use interfaces.
Types of inheritance:
1. Single Inheritance: Refers to inheritance in which there is only one base
class and one derived class. This means that a derived class inherits properties
from single base class.
2. Hierarchical Inheritance: Refers to inheritance in which multiple derived
classes are inherited from the same base class.
3. Multilevel Inheritance: Refers to inheritance in which a child class is derived
from a class, which in turn is derived from another class.
Q11. Constructors
• A constructor is called when an object is first created.
• The constructor is called with the same name as the class
• You can use a constructor to initialize objects and set any parameters.
• In addition, you can write constructors to accept argument.
Q14.Properties of an Array:
1. Length Property: User can access the length of an array which specifies the
number of elements that can be stored in the array.
Example: int len X. Length;
2. GetLowerBound(): User can find out lower boundary of an Array, returns an inter
bound value.
Example: X. Get LowerBound();
3. GetUpperBound(): User can find out upper boundary of an Array, returns an
integer bound value.
Example: X. GetUpperBound()