content

C# interview Questions

  1. What is the name of c#.net compiler?

Csc is the name of C# compiler.

  1. What is the main difference between delegate and an event in c#?

They aren't the same. An event is an event. A "delegate" assigns a particular event handler to an object instance. Thus, when an object event happens, the proper procedure/method is called.

An example might help. I frequently code things so that a single method is called for all instances of a class. No matter which button is clicked, call my generic "button_click" method. That method will use the event arguments to determine which button was actually clicked.

In order to assign all button click events to a single method, I have to code the delegates.

  1. What is the difference between shadow and override

Shadowing :- This is a VB.Net Concept by which you can provide a new implementation for the base class member without overriding the member. You can shadow a base class member in the derived class by using the keyword "Shadows". The method signature,access level and return type of the shadowed member can be completely different than the base class member.

Hiding : - This is a C# Concept by which you can provide a new implementation for the base class member without overriding the member. You can hide a base class member in the derived class by using the keyword "new". The method signature,access level and return type of the hidden member has to be same as the base class member.Comparing the three :-

1) The access level , signature and the return type can only be changed when you are shadowing with VB.NET. Hiding and overriding demands the these parameters as same.

2) The difference lies when you call the derived class object with a base class variable.In class of overriding although you assign a derived class object to base class variable it will call the derived class function. In case of shadowing or hiding the base class function will be called.

  1. Real life examples of polymorphisms, encapsulation and inheritance?

polymorphisms:-
polymorphisms is nothing but ability to take more than one forms(One Interface,Multiple Methods or One Name,Many Forms).

Encapsulation:-
-is nothing but wrapping the data and functions into single entity.

Inheritance:-
The Process of deriving new class from existing class.This is called Inheritance.
New Class-Child Class
Existing Class-Parent Class

Types:
*Single Inheritance
*Multiple
*Hybrid
*Multilevel
*Hierarchical

  1. What connections does Microsoft SQL Server support?

Windows Authentication (via Active Directory) and SQL Server authentication (via Microsoft SQL Server username and passwords).

  1. What does the keyword virtual mean in the method definition?

If a base class have a virtual method it means that method must be override by the derived class using override keyword.

  1. The C# keyword int maps to which .NET type

System.Int32

  1. Which class use to Read/Write data to memory

MemoryStream

It is a nonbuffered stream whose encapsulated data is directly accessible in memory(RAM not files on disk).

  1. XML documents for a C# program can be generated using

doc will generate xml documents

  1. What is an object? Define a class.

Class is a user defined abstract data type, which describes the attributes and behaviours of a real world object.

Object is an instance of a class.

  1. Does C# support multiple inheritance?

No, Instead of this, we can inheritance the multiple interface,

but C++ support multiple inheritance

  1. Define abstraction, encapsulation, inheritance: with example.

Abstraction: Abstraction works by abstracting common parts of objects and merging them into a single abstract class. An abstract class is a parent class that allows inheritance but can never be instantiated. Abstract classes contain one or more abstract methods that do not have implementation. Abstract classes allow specialization of inherited classes.

Encapsulation: The details of how objects worked are hidden to the user of that object.Like RGB colors.We define RGB internally what happened how complex is it is hidden from us.

Inheritance :Inheritance is the process of creating new classes, called derived classes, from existing classes.The derived class inherits all the capabilities of the base class, but can add embellishments and refinements of its own.

  1. Which debugging window allows you to see the methods called in the order they were called?

Call Stack Window is the only method to view order of Called method and this window is also useful to see methods called to get to the point at which execution halted

  1. What is mean "Death of Diamod"?

As every object is treated as a diamond in a Class we can say that destruction of a class object after it's functionality in order to recover the memory associated with this object is known as "Death of Diamond".

  1. What's the top .NET class that everything is derived from?

System. Object is the very base class from which all other objects are derived.

  1. How to use HASH TABLE,ARRAYLIST in c# explain with example?
The ArrayList object is a collection of items containing a single data value.

Items are added to the ArrayList with the Add() method.
The following code creates a new ArrayList object named mycountries and four items are added:

U can sort it alphabetically
mycountries.Sort()
By default, an ArrayList object contains 16 entries. An ArrayList can be sized to its final size with the TrimToSize() method:
mycountries.TrimToSize()
For reversing

mycountries.Reverse()
With DB
rb.DataSource=mycountries
rb.DataBind()



The Hashtable object contains items in key/value pairs. The keys are used as indexes, and very quick searches can be made for values by searching through their keys.

Items are added to the Hashtable with the Add() method.

The following code creates a Hashtable named mycountries and four elements are added:




With DB



AutoPostBack="True" />

17. How do I make a DLL in C#?

You need to use the /target: library compiler option.

18.How does one compare strings in C#?

In the past, you had to call .ToString() on the strings when using the == or != operators to compare the strings' values. That will still work, but the C# compiler now automatically compares the values instead of the references when the == or != operators are used on string types. If you actually do want to compare references, it can be
done as follows: if ((object) str1 == (object) str2) { ... }
Here's an example showing how string compares work: using System;
public class StringTest
{
public static void Main(string[] args)
{
Object nullObj = null;
Object realObj = new StringTest();
int i = 10;
Console.WriteLine("Null Object is [" + nullObj + "]n" +
"Real Object is [" + realObj + "]n" +
"i is [" + i + "]n");
// Show string equality operators
string str1 = "foo";
string str2 = "bar";
string str3 = "bar";
Console.WriteLine("{0} == {1} ? {2}", str1, str2, str1 == str2 );
Console.WriteLine("{0} == {1} ? {2}", str2, str3, str2 == str3 );
}
}
Output: Null Object is []
Real Object is [StringTest]
i is [10]
foo == bar ? False
bar == bar ? True

19 All the C# programs must have the following statement

Using system

20 Does C# support try-catch-finally blocks?

Yes. Try-catch-finally blocks are supported by the C# compiler.

21 Every statement in C# must end in

;

22 To Configure .Net for JIT activation what do you do

Actually JIT activation is required for COM+ components which can be done by setting JustInTimeActivation attribute to true (choice A). For .net applications / components JIT comes in by default.

23 All the .NET languages have the following in common

Basic class library

24 What is CLS?

The Common Language Specification (CLS) describes a set of features that different languages have in common.
The CLS includes a subset of the Common Type System (CTS).

25 How do you inherit from a class in C#?

class abc
{
}
class xyz:abc
{
}
means using collen in derived class....

26 What is Thread?
Use of Threads in c#.

Thread is nothing more than a process.On the computer thread is a process moving through time.Thread is analogous to the operating system process in which your application runs.Every application runs with atleast one thread.Threads run parallel within a single process.Threads share (heap) memory with ather threads running in the same application domain.Thread means to handle some repeatedly without interrupt other process.

27 What is CLR?

The .NET Framework provides a run-time environment called the common language runtime, which runs the code and provides services that make the development process easier.

 
Design by krish29786