Collection Classes

1. How many enumerators will exist if four threads are simultaneously working on an ArrayList object?  

  • A) 1
  • B) 3
  • C) 2
  • D) 4
  • E) Depends upon the Project Setting made in Visual Studio.NET.

2. What is an Array ? What are different ways of writing an Array ?  

Array is a datastructure that stores a collection of value that are of same data type. diff ways of writing an array are- a)specify the data length in declaration. int [] count= new int[5]; b) int[] count = new int[] { 1, 2, 3 }; skip the length but have to specify the value. c)int[] count = new int[2] { 1, 2, 3 }; both a and b. one thing should be taken care here the length of int array should be equal to number of values specified.

3. .Array is reference type or value type ?  

Reference Type

4. How do you search an item in an Array ?  

The BinarySearch static method of Array class can be used to search for an item in a array. . The method takes at least two parameters - an array and an object (the item you are looking for). If an item found in an array, the method returns the index of the item (based on first item as 0th item), else method returns a negative value. eg- string[] name = new string[] { "chai", "alex", "dave" }; int i=Array.BinarySearch(name, "dfsdf"); i returns a negative value.

5. .How to achieve Deep copy and Shallow copy using Array ?  

Deep Copy-- By using Array.CopyTo Shallow Copy---Array.Clone()

6. What are different types of an Array ?  

a) Single dimensional Array b) Multidimensional Array c) Jaggd Array

7. Where does array index starts ?  

Array index starts at Zero. Suppose you have int [] count= {1,2,3} then int[0] will give you "1".

8. How do you sort an item in Array in reverse order ?  

Use Count and Reverse property of an array. eg- int[] count = new int[] { 1, 2, 3,6,8,4 }; Array.Sort(count); Array.Reverse(count);

9. Find the maximum no in an array.  

you can use the property of array called Max or use the below algo-

10. Convert arraylist to string array  

Suppose you have a arraylist say with 3 string values- a[0]-name,a[1]-age,a[2]-gender.After converting using below code it will look like string.Join(",",(string[])a.ToArray(typeof(string))) string a=name,age,gender

11. What is ArrayList?  

Array is whose size can increase and decrease dynamically. Array list can hold item of different types. As Array list can increase and decrease size dynamically you do not have to use the REDIM keyword. You can access any item in array using the INDEX value of the array position.

12. What is a HashTable?  

You can access array using INDEX value of array, but how many times you know the real value of index. Hashtable provides way of accessing the index using a user identified KEY value, thus removing the INDEX problem.

13. What are queues and stacks?  

Queue is for first-in, first-out (FIFO) structures. Stack is for last in, first-out (LIFO) structures.

14. What is ENUM?  

It is used to define constants.

15. What is the difference between Class and structure’s?  

Following are the key differences between them:-
• Structures are value types and classes are reference types. So structures use stack and classes use heap.
• Structures members cannot be declared as protected, but class members can be. You cannot do inheritance in structures.
• Structures do not require constructors while classes require.
• Objects created from classes are terminated using Garbage collector. Structures are not destroyed using GC.

16. What are similarities between Class and structure?  

Following are the similarities between classes and structures:-
• Both can have constructors, methods, properties, fields, constants, enumerations, events, and event handlers.
• Structures and classes can implement interface.
• Both of them can have constructors with and without parameter.
• Both can have delegates and events.

17. Explain Structure.  

18. Explain Constructors of C# structure.  

In c#, a structure can have constructors. A constructor is a special member of the structure. It can be used to initialize variables of the structure when its object is created. The name of constructor must be the same as the name of structure. The constructor called automatically when the keyword "new" is used to create the objects of the structure.
struct student
    public string stnumber;
    public string stname;
    public string stsex;
    public student(string id,string name,string sex){ //constructor

student st=new student("s001","Dara Yuk","M"); //create object

Note: a structure in C# can have other members such as methods, properties, and events. However, if you have these kinds of things in your program, you should consider using class instead.

19. What is the difference between Array and Arraylist?  

In an array, we can have items of the same type only. The size of the array is fixed. An arraylist is similar to an array but it doesn’t have a fixed size.

20. What is the difference between Array and LinkedList?  

Array is a simple sequence of numbers which are not concerned about each others positions. they are independent of each others positions. adding,removing or modifying any array element is very easy. Compared to arrays ,linked list is a comlicated sequence of numbers.

.Net Interview Question

PHP Interview Question

Java Interview Question

AngularJS Interview Questions