We are providing online training of realtime Live project on Asp.Net MVC with Angular and Web API. For more information click here. If you have any query then drop the messase in CONTACT FORM

Tuesday, July 14, 2015



1.What is Array?

Ans: An array stores a fixed-size sequential collection of elements of the same type. An array is used to store a collection of data, but it is often more useful to think of an array as a collection of variables of the same type stored at contiguous memory locations.

All arrays consist of contiguous memory locations. The lowest address corresponds to the first element and the highest address to the last element.

2.What is difference between array and collection?

1) use an array when the number of elements that need to be inserted into the array is known at compile time and it remains fixed throughout the execution of the program. You use a collection when you do not know how many elements you will need to store. So basically a collection can grow in size dynamically. The data structure used to implement the collection depends on the collection type. e.g. for a Arraylist a doubly linked list may be used.

2) You can store elements of similar type only in an array. Unless ofcourse you declare an array of type 'Object'. In a collection you can store any type of elements provided they are all objects. You can store basic data types in an array. You can only store objects in a collection.

3.Why always start of index number is zero?


The compiler thinks that 0 is a positive number.
we have an integer range of
-128 to 127.
here -128 to -1 are negative numbers
and 0 to 127 are positive numbers
so array starts with the 0 as index.

4.What is the difference between arrays in C# and arrays in other programming languages?
Arrays in C# work similarly to how arrays work in most other popular languages There are, however, a few differences as listed below1. When declaring an array in C#, the square brackets ([]) must come after the type, not the identifier. Placing the brackets after the identifier is not legal syntax in C#.
int[] IntegerArray; // not int IntegerArray[];2. Another difference is that the size of the array is not part of its type as it is in the C language. This allows you to declare an array and assign any array of int objects to it, regardless of the array's length.int[] IntegerArray; // declare IntegerArray as an int array of any sizeIntegerArray = new int[10]; // IntegerArray is a 10 element arrayIntegerArray = new int[50]; // now IntegerArray is a 50 element array


5.What are the 3 different types of arrays that we have in C#?
1. Single Dimensional Arrays2. Multi Dimensional Arrays also called as rectangular arrays3. Array Of Arrays also called as jagged arrays

6.Are arrays in C# value types or reference types?
Ans:Reference types.

7.What is the base class for all arrays in C#?
System.Array

8.How do you sort an array in C#?
The Sort static method of the Array class can be used to sort array items.

9.What property of an array object can be used to get the total number of elements in an array?
Length property of array object gives you the total number of elements in an array. An example is shown below.
using System;
namespace ConsoleApplication
{
class Program
{
static void Main()
{int[] Numbers = { 2, 5, 3, 1, 4 };
Console.WriteLine("Total number of elements = " +Numbers.Length);
}}}

10.Give an example to show how to copy one array into another array?
We can use CopyTo() method to copy one array into another array. An example is shown below.
using System;

namespace ConsoleApplication
{
class Program
{
static void Main(){int[] Numbers = { 2, 5, 3, 1, 4 };
int[] CopyOfNumbers=new int[5];
Numbers.CopyTo(CopyOfNumbers,0);
foreach (int i in CopyOfNumbers){Console.WriteLine(i);
}
}
}
}

11.What’s the difference between the System.Array.CopyTo() and System.Array.Clone()?
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.
How can you sort the elements of the array in descending order?
By calling Sort() and then Reverse() methods.

12.What is array class?

Ans This class is defind under the System Namspace, which contains a set of properties, methods using which we can perform operations on an Array.

13.What are properties of array?


Ans:length and rank

14. What is difference between Length and Rank in Array?

Ans:Length:Get a 32-bit integer that represents the total number of elements in all dimensions of array.

Rank:Gets the rank(number of dimensions)of the array.for example a one-d array return 1,a two-dimensional array return 2 and so on.

15.What are method of array?

16.What is difference between Index of and last index of

17. what is difference between Empty and null?

Ans:

Use null when we want to represent that there is no value;

Use String.Empty when we want to represent that there is a value, but the value is a blank string.


18.What is Two dimensional array and What is syntax?

19.What is Mixed array ?

Ans: 
Mixed arrays are a combination of multi-dimension arrays and jagged arrays. Multi-dimension arrays are also called as rectangular arrays.

Understanding the Array Class

Arrays are extremely useful when you have several similar objects that you want to be able to process the same way or to be able to process as a group rather than individually.
The Array class, defined in the System namespace, is the base class for arrays in C#. Array class is an abstract base class, which can't be inherited, but it provides CreateInstance method to construct an array.
System.Array class provides methods for creating, manipulating, searching, and sorting arrays, thereby serving as the base class for all arrays in the common language runtime.



20.What is difference between for loop and foreach loop ?

21. What is GetLength method in array?

22.How to find the size of an array?

24.What is mean by Jagged array?


Ans: A special type of array is introduced in C#. A Jagged Array is an array of an array in which the length of each array index can differ. Example: A Jagged Array can be used is to create a table in which the lengths of the rows are not same. This Array is declared using square brackets ( [ ] ) to indicate each dimension.

25.What is binary search array?

Ans: It searches an array.sorting and searching algorithms enabled in this program. The Array.BinarySearch method has one version that accepts a type parameter, which you can specify in angle brackets.

26.What is Param array in C#?

Ans: This is used for passing unknown number of parameters to a function.

27.What is the use of GetCommandLineArgs() method in C#.NET?

Ans: With GetCommandLineArgs() method, the command line arguments can be accessed. The value returned is an array of strings.


27. Explain collection in .NET and describe how to enumerate through the members of a collection.

There are various collection types in .NET which are used for manipulation of data. Collections are available in System.Collections namespace

IEnumerator is the base interface for all enumerators. Enumerators can only read the data from the data collections but not modify them. Reset and MoveNext are the methods used with enumerators which bring it back to the first position and move it to the next element position respectively. Current returns the current object.




28.What is collection?
Ans: Collections provide a more flexible way to work with groups of objects. Unlike arrays, the group of objects you work with can grow and shrink dynamically as the needs of the application change. For some collections, you can assign a key to any object that you put into the collection so that you can quickly retrieve the object by using the key.

A collection is a class, so you must declare a new collection before you can add elements to that collection.

29.Difference between array and collection?

Ans: 1) use an array when the number of elements that need to be inserted into the array is known at compile time and it remains fixed throughout the execution of the program. You use a collection when you do not know how many elements you will need to store. So basically a collection can grow in size dynamically. The data structure used to implement the collection depends on the collection type. e.g. for a Arraylist a doubly linked list may be used.

2) You can store elements of similar type only in an array. Unless of course you declare an array of type 'Object'. In a collection you can store any type of elements provided they are all objects. You can store basic data types in an array. You can only store objects in a collection.

30.What are the class of collection?
Ans: ArrayList
HashTable
SortedList
BitArray
Queue
Stack

31. What is the difference between LinkedList and ArrayList
Ans: An ArrayList will use a system array (like Object[]) and resize it when needed. On the other hand, a LinkedList will use an object that contains the data and a pointer to the next and previous objects in the list

32. different types of collection in .NET?

Ans: Collection: - Collections are basically group of
records which can be treated as a one logical unit.

.NET Collections are divided in to four important categories as follows.

1. Indexed based.

2. Key Value Pair.

3. Prioritized Collection.

4. Specialized Collection.


33.What is indexed based collection?

Ans:It helps you to access the value of row
by using the internal generated index number by the collection.

34. What is Prioritized Collection ?

Ans:Prioritized Collection: -It helps us to get the element
in a particular sequence.

35.What is Specialized Collection.?

Ans. It is very specific collections
which are meant for very specific purpose like hybrid dictionary that start
as list and become hashtable.


36. Difference between Array and Arraylist in C# with Example
Ans.


These are strong type collection and allow to store fixed length

Array Lists are not strong type collection and size will increase or decrease dynamically


In arrays we can store only one datatype either int, string, char etc…

In arraylist we can store all the datatype values


Arrays belong to System.Array namespace

Arraylist belongs to System.Collection namespaces

37. Who perform faster?Array or Arraylist?Explaine?

Ans: As in ArrayList lots of Boxing and UnBoxing are done therefore its performance is slower than Array because in Array there is no type casting.


38. What are Advantages and Disadvantages of arrays?

Ans: Advantages:

1. It is used to represent multiple data items of same type by using only single name.
2. It can be used to implement other data structures like linked lists, stacks, queues, trees, graphs etc.
3. 2D arrays are used to represent matrices.

Disadvantages:

1. We must know in advance that how many elements are to be stored in array.
2. Array is static structure. It means that array is of fixed size. The memory which is allocated to array can not be increased or reduced.
3. Since array is of fixed size, if we allocate more memory than requirement then the memory space will be wasted. And if we allocate less memory than requirement, then it will create problem.
4. The elements of array are stored in consecutive memory locations. So insertions and deletions are very difficult and time consuming.

39. What are Applications or Uses of arrays?

1. It is used to represent multiple data items of same type by using only single name.
2. It can be used to implement other data structures like linked lists, stacks, queues, trees, graphs etc.
3. 2D arrays are used to represent matrices.
40. Describe the formula of finding the location (address) of particular element in 2D array using example.

Ans: Answer:

1. In case of Column Major Order:

The formula is:

LOC (A [J, K]) = Base (A) + w [M (K-1) + (J-1)]

Here

LOC (A [J, K]) : is the location of the element in the Jth row and Kth column.

Base (A) : is the base address of the array A.

w : is the number of bytes required to store single element of the array A.

M : is the total number of rows in the array.

J : is the row number of the element.

K : is the column number of the element.

41.What is Hashtable?


Ans: It uses a key to access the elements in the collection.

A hash table is used when you need to access elements by using key, and you can identify a useful key value. Each item in the hash table has a key/value pair. The key is used to access the items in the collection.

42.What is SortedList?

Ans: It uses a key as well as an index to access the items in a list.

A sorted list is a combination of an array and a hash table. It contains a list of items that can be accessed using a key or an index. If you access items using an index, it is an ArrayList, and if you access items using a key , it is a Hashtable. The collection of items is always sorted by the key value.

43.What is NameValueCollection?

Ans: NameValueCollection is used to store a collection of associated String keys and String values that can be accessed either with the key or with the index. It is very similar to C# HashTable, HashTable also stores data in Key , value format .

NameValueCollection can hold multiple string values under a single key. As elements are added to a NameValueCollection, the capacity is automatically increased as required through reallocation. The one important thing is that you have to importSystem.Collections.Specialized Class in your program for using NameValueCollection.

44.What is List Classes?

Ans: The Collection classes are a group of classes designed specifically for grouping together objects and performing tasks on them. List class is a collection and defined in the System.Collections.Generic namespace and it provides the methods and properties like other Collection classes such as add, insert, remove, search etc.

The C# List < T > class represents a strongly typed list of objects that can be accessed by index and it supports storing values of a specific type without casting to or from object.

45. How to find the size of a list?

You can use count property to know the number of items in the List collection or the length of a C# List

46.
How to Insert an Item in an ArrayList ?

You can use insert(index,item) method to insert an in the specified index.

47.How to add an Item in an ArrayList ?

Syntax : ArrayList.add(object)

48.How to remove an item from arrayList ?

Ans:
 Syntax : ArrayList.Remove(object)
object : The Item to be add the ArrayList

Exam.
arr.Remove("item2")

49.How to remove an item in a specified position from an ArrayList ?
Ans: Syntax : ArrayList.RemoveAt(index)
index : the position of an item to remove from an ArrayList

Exam.
ItemList.RemoveAt(2)

50.How to sort ArrayList ? 
Ans: Syntax : ArrayList.Sort()


51.What is stack class?

Ans: The Stack class represents a last-in-first-out (LIFO) Stack of Objects. Stack follows the push-pop operations. That is we can Push (insert) Items into Stack and Pop (retrieve) it back . Stack is implemented as a circular buffer. It follows the Last In First Out (LIFO) system. That is we can push the items into a stack and get it in reverse order. Stack returns the last item first. As elements are added to a Stack, the capacity is automatically increased as required through reallocation.

Commonly used methods : Push : Add (Push) an item in the Stack data structure
Pop : Pop return the last Item from the Stack


Contains: Check the object contains in the Stack

52.How To add a pair of value in HashTable Syntax : HashTable.Add(Key,Value)

Ans: Key : The Key value
Value : The value of corresponding key


Hashtable ht;
ht.Add("1", "Sunday");

53. How To Check if a specified key exist or not in hash table Synatx : bool HashTable.ContainsKey(key)

Ans: Key : The Key value for search in HahTable
Returns : return true if item exist else false
ht.Contains("1");

54. How To Check the specified Value exist in HashTable Synatx : bool HashTable.ContainsValue(Value)

Ans: Value : Search the specified Value in HashTable
Returns : return true if item exist else false

ht.ContainsValue("Sunday")

55. How To Remove the specified Key and corresponding Value Syntax : HashTable.Remove(Key)

Ans: Key : The key of the element to remove
ht.Remove("1");

56.What is BitArray?
Ans: It represents an array of the binary representation using the values 1 and 0.

It is used when you need to store the bits but do not know the number of bits in advance. You can access items from the BitArray collection by using an integer index, which starts from zero.

57.What are interface class in collection

Ans: IEnumerable

IEnumerator

ICollection

IList

IDictionary

58.What is GetHashCode method?

Ans: It returns the hash code for the current object. This method also serves as a hash function for a particular type. It is suitable for use in hashing algorithms and data structures like a hash table. This method can be overridden by the derive class. Object.GetHashCode() returns the same hash code for the same instance, but it is not necessary that it will return a different hash code for two different instances or the same hash code for two instances which have the same values. Different versions of the .NET Framework might also generate different hash codes for the same instance.

59.What is ToString method?

Ans: It returns the human readable string of the object that is culture specific. The default implementation returns the runtime type of the object. The derive class can override this method for returning meaningful value of the type. For example, the ToString() method of Double returns the string representation of the value that the object has.

60.What is GetEnumerator()?

Ans:
It returns the enumerator object that can be used to iterate through the collection. It allows using the foreach statement. Enumerators only allow reading the data in the collection.

61.What is IsFixedSize properties?

Ans: It returns true if IList has fixed size.

62.What is GetType()?

Ans: It returns the Type object of current instance. Type is the basis for using reflection in .NET. Use the members of Type to get information about a type declaration, such as the constructors, methods, fields, properties, and events of a class, as well as the module and the assembly in which the class is deployed.



63.What is ICollection Interface?


Ans: ICollection interface specifies a method for getting the size of collection, creating enumerators on a collection and managing synchronized access to all non-generic collections. It is a base interface for classes in theSystem.Collections namespace.

64.What is object class?

Ans: Object class is the base class of every type. All other types directly or indirectly derive from object class. Because of its lofty position, a .NET developer should have a good knowledge of the object class and its members.
65.What is queue class?
Ans: The Queue works like FIFO system , a first-in, first-out collection of Objects. Objects stored in a Queue are inserted at one end and removed from the other. The Queue provide additional insertion, extraction, and inspection operations. We can Enqueue (add) items in Queue and we can Dequeue (remove from Queue ) or we can Peek (that is we will get the reference of first item ) item from Queue. Queue accepts null reference as a valid value and allows duplicate elements.

66.What are the method of queue class?
Ans: Enqueue : Add an Item in Queue
Dequeue : Remove the oldest item from Queue


Peek : Get the reference of the oldest item

67.What is the use of assert() method?

Answer:
Assert method is in debug compilation. It takes a boolean condition as a parameter. It shows error dialog if the condition is false and if the condition is true, the program proceeds without interruption.

68.What is set in collection?

Ans: Sets. The HashSet implements set logic in its many instance methods. We use methods such as Union on different HashSets to solve problems. This makes some programs simpler.
HashSet
SortedSet




No comments: