This is first article on C# Interview Questions, primarily for beginners. This set of 21 C# Interview Questions is also useful for intermediates. These 21 Interview Questions on C-Sharp consist answer of questions asked in real interview for beginners. Go through the list and surely comment your feedback.
First 7: C# Interview Questions
1. What is C#?
C# is an object-oriented programming language developed by Microsoft. C# is designed for Common Language Infrastructure (CLI), which consists of the executable code and runtime environment that allows use of various high-level languages on different computer platforms and architectures.
2. What is the difference between ref and out parameters?
Output parameters are similar to reference parameters, except that they transfer data out of the method rather than into it. Reference parameter copies the reference to the memory location of an argument into the formal parameter. This means that changes made to the parameter affect the argument.
3. 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.
4. What is boxing in C#?
When a value type is converted to object type, it is called boxing.
5. What is unboxing in C#?
When an object type is converted to a value type, it is called unboxing.
6. What are value types in C#
Value type variables can be assigned a value directly. They are derived from the class System.ValueType. The value types directly contain data. Some examples are int, char, and float, which stores numbers, alphabets, and floating point numbers, respectively. When you declare an int type, the system allocates memory to store the value.
7. What are reference types in C#?
The reference types do not contain the actual data stored in a variable, but they contain a reference to the variables. In other words, they refer to a memory location. Using multiple variables, the reference types can refer to a memory location. If the data in the memory location is changed by one of the variables, the other variable automatically reflects this change in value. Example of built-in reference types are: object, dynamic, and string.
C-Sharp Interview Questions : Next 7
8. What is the purpose of an access specifier in C#?
An access specifier defines the scope and visibility of a class member.
9. 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.
10. 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.
11. 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.
12. What is scope of an 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.
13. 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.
14. 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.
Last 7 of 21 C# Interview Questions
15. What is inheritance?
One of the most important concepts in object-oriented programming 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.
When creating a class, instead of writing completely new data members and member functions, the programmer can designate that the new class should inherit the members of an existing class. This existing class is called the base class, and the new class is referred to as the derived class. The idea of inheritance implements the IS-A relationship. For example, person IS A human, Male IS-A person hence Male IS-A human as well, and so on.
16. How to inherit a class in C#?
A class can be derived from more than one class or interface, which means that it can inherit data and functions from multiple base classes or interfaces. The syntax used in C# for creating derived classes is as follows:
public class baseclass
class derived_class : base_class
17. What is polymorphism?
The word polymorphism means having many forms. In object-oriented programming paradigm, polymorphism is often expressed as “one interface, multiple functions”.
18. What is the difference between static polymorphism and dynamic polymorphism?
Polymorphism can be static or dynamic. In static polymorphism, the response to a function is determined at the compile time. In dynamic polymorphism, it is decided at run-time.
19. What is function overloading?
In practical, We can have multiple definitions for the same function name in the same scope.The definition of the function must differ from each other by the types and/or the number of arguments passed to the function. We cannot overload function declarations that differ only by return type.
Overloading Considerations parameters:
(a) Function return type No
(b) Number of arguments Yes
(c) Type of arguments Yes
20. What is a sealed class in C#?
Sealed means can not be inherited. When a class is declared sealed, it cannot be inherited.
21. What are virtual functions in C#?
When we have a function defined in a class that we want to be implemented in an inherited class(es) as per our requirement, we 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.
These are some important and mostly C-Sharp Interview Questions asked on different level of .NET interviews. If you found this article useful then don’t forget to like and share this first article on C# Interview Questions, so that we can be encouraged for writing such a post.