Important Interview Questions

Explain Managed Environment :

Code that operates within the CLR is called managed code. Managed code benefits from the services that the CLR offers, including garbage collection, memory management, security, etc.
Explain Unmanaged Environment :

Code that does not operate within the CLR is called unmanaged code. Unmanaged code does not get benefits offered by CLR including garbage collection, memory management, security, etc. Eg. COM components are unmanaged code.

ArrayList Concept in .Net


Provides a collection similar to an array, but that grows dynamically as

the number of elements change.

Example

static void Main()
{
ArrayList list = new ArrayList();
list.Add(11);
list.Add(22);
list.Add(33);
foreach(int num in list)
{
Console.WriteLine(num);
}
}

Output
11
22
33

Stack Concept in .Net


A collection that works on the Last In First Out (LIFO) principle,

i.e., the last item inserted is the first item removed from the collection.
Push - To add element and
Pop – To Remove element

Example

using System;
using System.Collections;

class Test
{
static void Main()
{
Stack stack = new Stack();
stack.Push(2);
stack.Push(4);
stack.Push(6);

while(stack.Count != 0)
{
Console.WriteLine(stack.Pop());
}
}
}

Output

6
4
2

Queue Concept in .Net


A collection that works on the First In First Out (FIFO) principle, i.e.,

the first item inserted is the first item removed from the collection.
Enqueue - To add element and Dequeue – To Remove element
Example:


static void Main()
{
Queue queue = new Queue();
queue.Enqueue(2);
queue.Enqueue(4);
queue.Enqueue(6);

while(queue.Count != 0)
{
Console.WriteLine(queue.Dequeue());
}
}


Output
2
4
6

Hashtable Concept in .Net

Provides a collection of key-value pairs that are organized

based on the hash code of the key.

Example:
static void Main()
{
Hashtable ht = new Hashtable(20);
ht.Add("ht01", "DotNetGuts");
ht.Add("ht02", "EasyTutor.2ya.com");
ht.Add("ht03", "DailyFreeCode.com");

Console.WriteLine("Printing Keys...");
foreach(string key in ht.Keys)
{
Console.WriteLine(key);
}

Console.WriteLine("\nPrinting Values...");
foreach(string Value in ht.Values)
{
Console.WriteLine(Value);
}

Console.WriteLine("Size of Hashtable is {0}", ht.Count);

Console.WriteLine(ht.ContainsKey("ht01"));
Console.WriteLine(ht.ContainsValue("DailyFreeCode.com"));

Console.WriteLine("\nRemoving element with key = ht02");
ht.Remove("ht02");

Console.WriteLine("Size of Hashtable is {0}", ht.Count);

}


Output

Printing Keys...
ht01
ht02
ht03

Printing Values...
DotNetGuts
EasyTutor.2ya.com
DailyFreeCode.com


Size of Hashtable is 3
True
True
 
Removing element with key = ht02
Size of Hashtable is 2


SortedList Concept in .Net



Provides a collection of key-value pairs where the items are sorted according to the key. The items are accessible by both the keys and the index.
Example:
static void Main()
{
SortedList sl = new SortedList();
sl.Add(18, "Java");
sl.Add(5, "C#");
sl.Add(11, "VB.Net");
sl.Add(1, "C++.Net");

Console.WriteLine("The items in the sorted order are...");
Console.WriteLine("\t Key \t\t Value");
Console.WriteLine("\t === \t\t =====");
for(int i=0; i{
Console.WriteLine("\t {0} \t\t {1}", sl.GetKey(i),
sl.GetByIndex(i));
}
}



Output

Key Value

==
1 C++.Net
5 C#
11 VB.Net
18 Java


for more ex: http://dng-collections.blogspot.com/

Read Users' Comments (0)

0 Response to "Important Interview Questions"

Post a Comment