Link Search Menu Expand Document

C# Interview Questions For 10 Years Experience

Q1. What is the use of the method "hiding" in inheritance?

Answer:  Method hiding is a concept in Inheritance that is used to hide the methods of the base class from the derived class. If both have a method with the same name, method hiding comes into the picture. By providing a new keyword, one can simply hide the implementation of the methods of base/ child class from parent/derived class.

Q2. What is the difference between ref and out keywords?

Answer: ref keyword

1.Used when a called method has to update the passed parameter.

  1. It gives the option to pass data in a bidirectional way.
  2. Before passing a variable as a ref, it is necessary to initialize it unless the compiler will throw an error.

out method

1.Used when a called way has to update multiple passed parameters.

  1. Helps to get data in a unidirectional way.
  2. Requires no initialization while using the "out" keyword.

Q3. What do you mean by object pooling?

Answer: Object pooling is a software creational design pattern and a container of objects that holds a list of other entities that are ready for use. Once a user takes the object from the pool, it is not available in the pool until it is put back. It reduces the load of the CPU by keeping track of the data.

Q4. What is Reflection? State its uses.

Answer: Reflection is a process that gives metadata information on types, modules, assemblies, etc., at runtime.

Some of the Common use of Reflection:

  • Load assemblies at the given runtime
  • It helps to understand how a group defines a particular item, such as a class or enumeration.
  • List a class's field, properties, constructors, event, and methods
  • Get information about a property such as a type and if it is read-only
  • Get and Set the property's value.
  • Get information about the item's attribute etc.

Q5. Define the console application.

Answer: The console application is an application that takes inputs and displays output at the command prompt in Windows with the access of three basic streams, i.e., standard input, standard output, and standard error. For any beginner on C#, building a console application is ideally the first step, to begin with.

Q6. Describe the difference between error and exception.

Answer: In simple words, we can say an error occurs due to syntax problems, leading to a compilation error. It could also happen due to system resource unavailability, while an exception is a runtime error that occurs during the application’s execution and creates problems in the implementation. They can be removed by using the try-catch blocks mechanism.

Q7. How to specify what version of the framework your application is targeting?

Answer: The framework’s specification can be done simply by defining the “target framework” on the web. Config file, which was introduced in asp.net 4.0.

Below is the syntax used :

<?xml version=”1.0”?>
<configuration>
<system.web>
<compilation targetFramework=4.0>
</configuration>

Q8. How do you give a C# Autoproperty a default value?

Answer: Below Code for C# 5

class person()
{
public person()
{
Name="default name";
}
public string Name{get;set;}
}

 

Below Code for C# 6.0

Public string Name {get;set}="Default name"

Q9. What is the use of namespace?

Answer: Namespaces are used to provide a “named space” in which your application resides. They provide a level of separation of codes. The class names declared in one namespace does not conflict with the same class names displayed in another.

Q10. Write a code to generate a random number in C#?

Answer: The random number can be created by using a random class.

Syntax

//Example:
Random r = new Random();
int n = r.Next();

Other useful articles:


Back to top

© , C Sharp Online — All Rights Reserved - Terms of Use - Privacy Policy