C# Interview Questions and Answers (958) - Page 31

How many values can be returned from a method in C#?

We can return only one value from method or function,but we can use ref or out variable to change more than one value in called method.
What keyword is used to accept a variable number of parameter in a method?

Params keyword is used as to accept variable number of parameters.We use params keyword inside function parameters.It has array values.

For Example:-

public int sum_of_numbers(params int[] values)

{
}

In what situations Garbage collection can happen?

The Garbage collection can happen in the following three situations:-

1. The free physical memory of System is low.
2. The memory allocated on managed heap is more than a
pre- defined value.This value changes as the process runs.
3. The GC.Collect() method is called
What is the use of Enums in C#?

Enums or Enumerators are used to declare a set of related constants by-default they start with 0 index position.They are only available with primitive data types like int and short etc.

public enum CRUD_operations

{
add,
update,
delete
}

How to get values from Enum?

Suppose i have below Enumeration values:-

public enum WeekDays

{
Sunday,
Monday,
Tuesday,
Wednesday,
Thursday,
Friday,
Saturday
}


To get the values from Enum,we will write:-

int value1 = (int)WeekDays.Sunday; //output = 0;

string value2 = WeekDays.Sunday; //output = Sunday;

Describe the ways of cleaning an objects?

There is a perfect tool provided by Dot Net framework called Garbage collector,where with the help of GC,we can clean up the object and reclaim the memory.The namespace used is System.GC.

Other way is Dispose.For that we have to implement IDisposable Interface.

We the help of Finalize,we can also remove unmanaged objects.
What do we mean by Constructor?

Whenever we create object of a class,then constructor is called.
Constructor is a method in the class which has the same name as the class(in VB.Net it's New()).
It initializes the member attributes whenever an instance of the class is created.
It has no return type.
What is a Static class in C#?

Static class is a class which can be used or accessed without creating an instance of the class.

Static class has following features:-
1. Static class only contains static members and a private constructor.
2. Static class cannot be instantiated i.e. we can create object of Static Class because they are Private.
3. Static classes are sealed by default and therefore cannot be inherited.
What is ngen Utility?

The native image generator (ngen.exe) is a tool that improves the performance of managed applications.
Ngen.exe creates native images which are files containing compiled processor-specific machine code and instals then into the native image cache on the local computer.
The run time can use native images from the cache instead of using just-in-time(JIT) compiler to compile the original assembly.
Virtual inheritance can be stopped by declaring override as

NOTE: This is objective type question, Please click question title for correct answer.
Which of the following statement is true with respect to polymorphism?

NOTE: This is objective type question, Please click question title for correct answer.
Which of the following statement is true?

NOTE: This is objective type question, Please click question title for correct answer.
How many times can a constructor be called during the life time of an object?

NOTE: This is objective type question, Please click question title for correct answer.
What is the work of GC?

GC stands for Garbage Collector.As the name it collects garbage i.e. it removes those objects which are not used anywhere in the application.It runs internally.
We do not know when this will run.GC removes unmanaged resources from application.
Found this useful, bookmark this page to the blog or social networking websites. Page copy protected against web site content infringement by Copyscape

 Interview Questions and Answers Categories