0% found this document useful (0 votes)
17 views6 pages

Dot Net 3

Dot net

Uploaded by

Siddhi Sonawane
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
17 views6 pages

Dot Net 3

Dot net

Uploaded by

Siddhi Sonawane
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 6

Dot Net 3

Q1. data types in C#


• C# mainly categorized data types in two types:
(a) Value Types: Value types include simple types such as int, float, bool and char also
include Enum types, struct types and Nullable value.
(b) Reference Types: Reference types include class types, interface types, delegate
types and array types.

Q2. Struct type from Value type


• Struct types are a special form of classes having the properties of value types.
• As you know that the value types are stored on the stack; inherently the struct
type are also stored on the stack.
• The struct types can be copied and created efficiently, as stacks are the efficient
and convenient means of storing and accessing the types.
• The struct types encapsulate small group of related variables, they can contain
constructors, methods, properties, operators, events, nested types, indexes,
constants etc.
• While creating the struct type, you should remember that struct members cannot
be declared as protected as they fail to support inheritance.
• User can create struct type by using the struct keyword, when user create a struct
object and assign it to a variable, the variable holds the value of the struct object.

Q3. Enumeration type


• Enumerations are user-defined integer data types that are declared using the
enum keyword.
• Using enumeration, you can define a set of named integral constants that can
be assigned to a variable.
• Enumerations are strongly typed constants, which allow you to assign
symbolic names to integral values.
Q4. c# built-in reference types
1. Dynamics Type
2. Object Type
3. String Type

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

Q9. types of keywords for Method Overriding:


1. virtual keyword: This modifier or keyword use within base class method. It is used
to modify a method in base class for overridden that particular method in the
derived class.
2. override: This modifier or keyword use with derived class method. It is used to
modify a virtual or abstract method into derived class which presents in base class.
3. base Keyword: This is used to access members of the base class from derived class.
It basically used to access constructors and methods or functions of the base class. 0
Base keyword specifies which constructor of the base class should be invoked while
creating the instances of the derived class.

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.

Q 12. Why Access Modifiers?


• To control the visibility of class members
• To achieve "Encapsulation", this is the process of making sure that "sensitive"
data is hidden from users.
• Access modifiers help to avoid jumbling of data and methods with the existing
code as well as protect an object of a class from outside interference.
• These modifiers do this by defining a certain scope to access data and
methods in a restricted manner.
• You can declare a class and each of its methods with an access modifier.
List of modifiers:
1. public modifier: Allows public access to members both inside and outside a class
without any restrictions.
2. internal modifier: Allows internal access to members. Only the current assembly
can access these members. If a member of the internal accessibility level is accessed
outside the assembly in which it has been defined, an error is generated.
3. protected modifier: Allows protected access to members. You can access
protected members from either the class in which they are declared or a class
derived from the class in which they are declared
4. private modifier: Allows private access to members. Private members have the
least access permission level; you can either access them within the body of the class
or in the structure in which they are declared.
5. protected internal modifier: Allows access to the members of the current
assembly, the containing class, and the class derived from the containing class.

Q13. Use of 'this' Keyword:


• The this keyword refers to the current instance of a class.
• With the this keyword, you can access an instance of a class and use it with
instance methods, instance constructors and instance properties.

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()

You might also like