Floating FB popout byF5debug

Interview Questions and Answers on .Net Framework, OOPS, ASP.Net, C#.Net, SQL Server, WCF Series – Part 12

 

Question 111 – What is the Constructor of Hashtable?

  • We have ten overloaded Constructor. we will see some important constructors of Hashtable.
  • Constructor with no parameters - Creates an empty Hashtable.
  • Constructor with an Integer Parameter - Creates an empty Hashtable.
  • Adding an element to the Hashtable  -- hashobject.Add(Key as Object, value as Object)
  • Accessing an element in the Hashtable -- hashobject.Item({key})
  • Deleting a Particular element -- hashobject.Remove(Key as object)


Question 112 – What is an Array?

  • Arrays are mechanisms that allow you to treat several items as a single collection.
  • All array types are implicitly derived from System.Array, which itself is derived from System.Object. This means that all arrays are always reference types which are allocated on the managed heap. There are 4 types of arrays as below.
        • Single Dimensional Array
        • Mutidimensional Array
        • Jagged Array
        • Mixed Array


Question 113 – What is a Single-dimensional arrays?

  • Single-dimensional arrays have a single dimension
  • Syntax - int[] i = new int[50];


Question 114 – What is a Multidimensional arrays?

  • A multidimensional array is an array with more than one dimension.
  • Multidimensional arrays are also called rectangular arrays because each row will be the same length.
  • Syntax : int[,] squareArray = new int[3, 2] { { 1, 2 }, { 3, 4 }, { 5, 6 } };


Question 115 – What are Jagged arrays?

  • One can create multidimensional arrays with irregular dimensions, using jagged arrays.
  • Jagged arrays are often called array of arrays. An element of a jagged array itself is an array.
  • For example, you can define an array of names of students of a class where a name itself can be an array of three strings - first name, middle name and last name. Another example of jagged arrays is an array of integers containing another array of integers.
  • Syntax : int[][] numArray = new int[][] { new int[] { 1, 3, 5 }, new int[] { 2, 4, 6, 8, 10 } };

Question 116 – What are Mixed Arrays?

Mixed arrays are a combination of multi-dimension arrays and jagged arrays.


Question 117 – What is an ArrayList?

  • An ArrayList is an array that can dynamically grow and shrink.
  • The arraylist is more dynamic, you can add and remove items without losing performance. With the ArrayList class, you can
        • add new items to a list
        • insert items inside a list
        • arrange items of a list
        • check the existence of an item in a list
        • remove an item from the list
        • inquire about the list
        • destroy the list.
  • using Sort on ArrayList or on Array is faster than most custom implementations. Because TrySZSort method used in the base class libraries is implemented in native code, it has been heavily optimized.
  • Example : ArrayList list = new ArrayList();


Question 118 – What is the difference between Array and Array List?

Array
ArrayList
Array is in the System namespace. ArrayList is in the System.Collections namespace.
The capacity of an Array is fixed ArrayList can increase and decrease size dynamically
An Array is a collection of similar items ArrayList can hold item of different types
An Array can have multiple dimensions ArrayList always has exactly one dimension
Char[] vowel=new Char[]; ArrayList a_list=new ArrayList();
Array is a primitive data structure, which stores the values in indexed format. ArrayList is a more like a vector. (A re-sizeable array). It is a collection and stores any value as an object.

 

Question 119 – What is the Difference between Array and Collections?

  • Array are of fixed size, yes, it can be resized using Redim and Preserve. But for a Collection we can keep adding elements to it.
  • Arrays can store only one data type(Other than object array) whereas collections can hold any objects.
  • Accessing the element is very simple and very fast in collections.
  • Removing the element in Collection is very simple, in the case of arrays we need to shift the entire set of value up and reduce the size.


Question 120 – What is the difference between Array.Copy and Array.Clone?

Array.Copy:

  • Array.copy copies all data and structure.
  • performs a deep copy of the array.
  • CopyTo() copies the elements from the original array to the destination array starting at the specified destination array index.
  • The CopyTo() method copies the elements into another existing array.

Array.Clone

  • Array.clone copies only structure not data(ie only shadow part)
  • performs a shallow copy of the array.
  • Clone() method makes a clone of the original array.  It returns an exact length array.
  • The Clone() method returns a new array (a shallow copy) object containing all the elements in the original array.

 

Disclaimer – F5debug Interview Questions & Answers Series:

You may recopy extracts from these pages ("the material") to individual third party websites or to any intranet websites, but only if:

You acknowledge www.f5debug.net as the source of the material. Such acknowledgment should include reference to www.f5debug.net in the copy of the material and should also include “© Karthikeyan Anbarasan, www.f5debug.net ". You inform the third party that these conditions apply to him/her and that he/she must comply with them.

 

About Author: Karthikeyan Anbarasan, Microsoft MVP (Most Valuable Professional) in ASP.NET/IIS Architecture. He is the Founder and Chief Editor of the www.f5debug.net website and has authored books on Windows Phone and Business Intelligence(SSIS). He is also a Passionate Speaker and a Blogger on Microsoft Technologies.

You can Join Me On: Facebook, Twitter, Google Plus, LinkedIn

Add comment

  Country flag

biuquote
  • Comment
  • Preview
Loading

Recent Posts

Random Posts

Most Viewed

URL Shortner

Create your own short urls!!!

Site Counter

free counters

Disclaimer

This is a personal weblog. The opinions expressed here represent my own and not those of my employer. For accuracy and official reference refer to MSDN/ TechNet. I have documented my personal experience on this blog.

Protected by Copyscape Web Plagiarism Finder

Site Meter