CSharp Interview Questions and Answers For Freshers Part-3
21.What is scope of a public member variable of a C# class?
Public access specifier allows a class to expose its member variables and member functions to other functions and objects. Any public member can be accessed from outside the class.
22.What is scope of a private member variable of a C# class?
Private access specifier allows a class to hide its member variables and member functions from other functions and objects. Only functions of the same class can access its private members. Even an instance of a class cannot access its private members.
23.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.
24.What is scope of a Internal member variable of a C# class?
Internal access specifier allows a class to expose its member variables and member functions to other functions and objects in the current assembly. In other words, any member with internal access specifier can be accessed from any class or method defined within the application in which the member is defined.
25.What is scope of a Protected Internal member variable of a C# class?
The protected internal access specifier allows a class to hide its member variables and member functions from other class objects and functions, except a child class within the same application. This is also used while implementing inheritance.
26.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.
For example, you can store any value from -2,147,483,648 to 2,147,483,647 or null in a Nullable<Int32> variable. Similarly, you can assign true, false, or null in a Nullable<bool> variable.
27.What is the use of Null Coalescing Operator (??) in C#?
The null coalescing operator is used with the nullable value types and reference types. It is used for converting an operand to the type of another nullable (or not) value type operand, where an implicit conversion is possible.
If the value of the first operand is null, then the operator returns the value of the second operand, otherwise it returns the value of the first operand.
28.Can you create a function in C# which can accept varying number of arguments?
By using the params keyword, a method parameter can be specified which takes a variable number of arguments or even no argument.
29.Can you pass additional type of parameters after using params in function definition?
No! additional parameters are not permitted after the params keyword in a method declaration. Only one params keyword is allowed in a method declaration.
30.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.