Collection of Interview Questions on  CSharp

1. What do you mean by Object Oriented Programming?

It is a problem solving technique to develop software systems. It’s a technique to think real world in terms of objects. Object maps the software model to real world concept. These objects have responsibilities and provide services to application or other objects.

2. What is a Class?

A class describes all the

By: Pankaj Kumar Gupta   |    On:  10 Mar 2011 09:23:26

Code

try
            {
                try
                {
                    throw new ApplicationException();
                }
                finally
                {
                    throw new SystemException();

                }

            }
            catch (Exception ex)
            {

                Console.WriteLine(ex.GetType().Name);
            }

Output

SystemException.

Reason

When ApplicationException is raise, it will goes to within the  exception stack, and the  finally block also will run and throw system exception, now system exception also goes to within the exception stack.But when we are print within catch, system exception is most recently added, this is will be retrieved first from stack.so SystemException is result for above code.

 

By: RRaveen   |    On:  10 Feb 2011 01:59:30

Code

var data = "name";
data = 8;
Console.WriteLine(data);

Options

  1. output is 8
  2. its does not compile

Answer:

Its does not compile(option 2).

var keyword is implicit type, so once you are declared  as a specific type, then it  has decide the type automatically with right hand side value.so it won't compile. 

By: RRaveen   |    On:  10 Feb 2011 01:54:06

Answer:

var

If you are use the var keyword, then it valid type against right side value on declaration time

Example:

var data = "name";            
Console.WriteLine(data);

Here var will be string type at compile time.

dynamic

If you are use the dynamic keyword, the type will be decide on run time.

Example:

dynamic data = "name";
data = 8;
Console.WriteLine(data);

it will compile without any error, at run time data variable type is a int than string.because in the second line of code, you have change to string to in value on right hand side.

By: RRaveen   |    On:  10 Feb 2011 01:49:02

Answer:

Yes,refer below sample code

C# Code

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ConsoleApplication1
{
    public class TryCatch
    {
        static TryCatch()
        {

        }
    }
}

 

By: RRaveen   |    On:  22 Dec 2010 10:05:45

Answer:

If you want to prevent a class to create subclass, the class must be sealed. Most of the security classes are sealed.

Sample Code

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ConsoleApplication1
{
    public sealed class TryCatch
    {
        public void SaveEmployee(string empID)
        {

               // few line of code here            
            
        }
    }
}

 

By: RRaveen   |    On:  22 Dec 2010 10:01:39

Answer:

  1. Different parameter data types
  2. Different number of parameters
By: RRaveen   |    On:  22 Dec 2010 09:57:09

Answer:

The Array has two methods to perform copy operation such as Clone() and CopyTo().The Clone() method returns a new array (a shallow copy) object containing all the elements in the original array. The CopyTo() method copies the elements into another existing array. Both perform a shallow copy. A shallow copy means the contents (each array element) contains references to the same object as the elements in the original array. A deep copy (which neither of these methods performs) would create a new instance of each element's object, resulting in a different, yet identacle object.

By: RRaveen   |    On:  22 Dec 2010 09:42:11

Answer:

1.Call Sort() method for Array Then

2.Reverse() Method for Array.

Sample Code

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {

            string[] sample = new string[] { "RRaveen", "John", "Murukan", "Dhan" };            
            Array.Sort(sample);
            Array.Reverse(sample);

            for (int i = 0; i < sample.Length; i++)
            {
                Console.WriteLine(sample[i]);
                
            }
            Console.ReadLine();
         }
     }
}

Output

RRaveen
Murukan
John
Dhan
By: RRaveen   |    On:  22 Dec 2010 09:39:02
^ Scroll to Top