Home Interview Questions and AnswersTechnical Interview Questions and Answers.NETC# CSharp Interview Questions and Answers For Freshers Part-2

c-sharp-img11.What is boxing in C#?
When a value type is converted to object type, it is called boxing.

12.What is unboxing in C#?
When an object type is converted to a value type, it is called unboxing.

13.What are dynamic type variables in C#
You can store any type of value in the dynamic data type variable. Type checking for these types of variables takes place at run-time.

Syntax for declaring a dynamic type is −

dynamic <variable_name> = value;
For example,

dynamic d = 20;

14.What is the difference between dynamic type variables and object type variables?
Dynamic types are similar to object types except that type checking for object type variables takes place at compile time, whereas that for the dynamic type variables takes place at run time.

15.What are pointer types in C#?
Pointer type variables store the memory address of another type. Pointers in C# have the same capabilities as the pointers in C or C++.

Syntax for declaring a pointer type is −

type* identifier;
For example

char* cptr;
int* iptr;

16.What is the purpose of is operator in C#?
is operator determines whether an object is of a certain type.

If( Ford is Car) // checks if Ford is an object of the Car class.

17.What is the purpose of as operator in C#?
as operator casts without raising an exception if the cast fails.

Object obj = new StringReader(“Hello”);
StringReader r = obj as StringReader;

18.What is encapsulation?
Encapsulation is defined ‘as the process of enclosing one or more items within a physical or logical package’. Encapsulation, in object oriented programming methodology, prevents access to implementation details.

19.How encapsulation is implemented in C#?
Encapsulation is implemented by using access specifiers.

20.What is the purpose of an access specifier in C#?
An access specifier defines the scope and visibility of a class member.

You may also like

Leave a Comment