“C #” Interview Question

“C #” Interview Question

“C #” साक्षात्कार प्रश्न

1.What is namespace in C#?
->A namespace is designed for providing a way to keep one set of names separate from another. The class names declared in one namespace does not conflict with the same class names declared in another.

2.Which of the following ways to create an object of the Sample class given below will work correctly?

class Sample
int i;
Single j;
double k;
public Sample (int ii, Single jj, double kk)
i = ii;
j = jj;
k = kk;
(A) Sample s3 = new Sample(10, 1.2f, 2.4); (B) Sample s2 = new Sample(10, 1.2f); (C) Sample s1 = new Sample(, , 2.5); (D) Sample s1 = new Sample(10);
->The answer is (A) Sample s3 = new Sample(10, 1.2f, 2.4);

3.Which of the following in not service model (three-tier application) in c sharp?
(A) Presentation (UI) (B) Business (logic and underlying code) (C) Database (for storing the data) (D) Data (from storage or other sources)
->Answer is (C) Database (for storing the data)

4.Which of the following statements is correct?
(A) A constructor can be used to set default values and limit instantiation. (B) Destructors are used with classes as well as structures. (C) A class can have more than one destructor. (D) C# provides a copy constructor.

->The answer is (A) A constructor can be used to set default values and limit instantiation.

5.What is the purpose of using statement in C#?

->’using’ is a keyword in C# programming. It is used to include a namespace to a program. A program can have several namespace with several using keywords.

6.What is unboxing in C#?
->Converting from object type to a value type is known as unboxing in C#.

7.Which of the following are not types of access modifiers in C#?
(A) external protect (B) internal protect (C) protect (D) internal
->The answer is (A) external protect.

8.Which keyword is used to achieve shadowing in C#?
(A) Abstract (B) New (C) Shadow (D) Sealed

->The correct answer is (B) New.

9.What are dynamic type variables in C#
->Dynamic data type variable can hold any type of data. The type of the variable is checked at the run-time. Example: we can declare a dynamic variable like-
dynamic d=30;

10.What are pointer types in C#?
->Pointer type variable in C# stores the memory address of another variaable.Pointers in C# have the same capabilities as the pointers in C or C++.We can declare a pointer in C# like- char* cptr; where ‘char*’ represents a type i.e. character type pointer and ‘cptr’ represents the name of the pointer.

11.Different ways a method can be overloaded in C#.NET
(A) Different parameter data types (B) Different order of parameters (C) Different number of parameters (D) All of above
->The answer is (D) All of above.

12.Which file contains configuration data for each unique URl resource used in project?
(A) web.config (B) global.asax (C) webapplication.vsdisco (D) assemblyinfo.cs
->(A) web.config

13.What is scope of a protected member variable of a C# class?
->Protected access specifier allows a child class to access the member variables and member functions of its base class. This way it helps in implementing inheritance.

14.What are nullable types in C#?
C# provides a special data types, the nullable types, to which you can assign normal range of values as well as null values.

15.Which class acts as a base class for all arrays in C#?
->The Array class is the base class for all the arrays in C#. It is defined in the System namespace. The Array class provides various properties and methods to work with arrays.

16.What is the default access for a class?
->’internal’ is the default type of a class.

17.What is inheritance?
->Inheritance allows us to define a class in terms of another class, which makes it easier to create and maintain an application. This also provides an opportunity to reuse the code functionality and speeds up implementation time.

18.How can we sort the elements of the array in descending order?
->We can sort elements of an array by calling Sort() and then calling Reverse(). The Sort() will sort the elements in ascending order and then Reverse() will arrange it in descending order.

19.Which of the following class cannot be inherited?
(A) Abstract (B) Sealed (C) Both

->The answer is (B) Sealed.

20.What are virtual functions in C#?
->When you have a function defined in a class that you want to be implemented in an inherited classes, you use virtual functions. The virtual functions could be implemented differently in different inherited class and the call to these functions will be decided at runtime.

21.What is a preprocessor directives in C#?
-) The preprocessor directives give instruction to the compiler to preprocess the information before actual compilation starts.