C# Exclusive Interview Questions and Answers (453) - Page 21

  • A joint initiative from DotNetFunda.Com and Questpond.
  • A one stop place on the internet to get trusted and proven Interview Questions (based on more than a decade of experience in this field) to ensure the success of the candidates.
  • You will find almost all Interview questions from Questpond here and this list is growing day by day with all latest and updated interview questions.

453 records found.

Get 650+ Questpond's Interview videos on discount

________ to check whether the thread is dead or alive.

NOTE: This is objective type question, Please click question title for correct answer.
____________________ is a block of code which can be executed by only one thread at any given instance of time.

NOTE: This is objective type question, Please click question title for correct answer.
Locking _________ throughput.

NOTE: This is objective type question, Please click question title for correct answer.
___________________ is a synchronized resource managed by the OS.

NOTE: This is objective type question, Please click question title for correct answer.
What are the advantages of Generics

1. Generics solve the problem of type safety

2. Code Reusability: if we write a Generic Class or method once we can use that through out our program. hence it is code reuse

3. Performance: By using Generics performance increases ,this is because we are not using the concept of Boxing

4 Generic methods can often be called without employing any special syntax by using a feature called type inference
What are Generics in C#.Net

The generics feature in C# has been introduced with version 2.0 of the .NET Framework and these arejust like templates in C++. Using generics we can
create classes,methods, events, delegates which work with any type (like int, string, myclass etc). The Advantages with Generics are Performance will
increase, Code Reusability and Type Safety.
What is Generic class ? What is the purpose of Generic class

Generic class is not specific to any particular Data Type, but the instance of
that class is specific to the data type at the time of creating the
instance of the class.


For every data type the generic class is generated, a separate instance of the class is loaded by the class loader in CLR.
Define Collections in .NET and briefly explain its types

From a .NET perspective, a collection could be defined as an object that
implements one or more of the System.Collections.ICollection,
System.Collections.IDictionary, and System.Collections.IList interfaces.
This definition leads to my classification of the "built-in"
collections found in the System.Collections namespace into three broad
categories:



•Ordered collections: Collections that implement only the
ICollection interface are usually distinguished by the fact that
insertion order controls the order in which objects may be retrieved
from the collection. The System.Collections.Stack and
System.Collections.Queue classes are both examples of ICollection
collections.



•Indexed collections: IList-implementing collections are
distinguished by the fact that their contents can be retrieved via a
zero-based numeric index, like an array. The
System.Collections.ArrayList object is one example of an indexed
collection.



•Keyed collections: Collections implementing the IDictionary
interface contain items that can be retrieved by an associated key value
of some kind. The contents of IDictionary collections are also usually
sorted in some fashion based on the key value and can be retrieved in
sorted order by enumeration. The System.Collections.HashTable class
implements the IDictionary interface
What is IEnumerable interface

IEnumerable interface exposes the enumerator, which supports a simple iteration over a non-generic collection and it is forward only.
What is Array List in .Net

Array list is a type which similar to an Array. We will specify the size for
the Array which will never going to change in its life time. But In
Array List, the size gets dynamically increases when needed.

Example:

Using System.Collections;

Public static void main(String[] args)

{

ArrayList arrList = new ArrayList();

arrList.Add(11);

arrList.Add(12);

arrList.Add(13);

arrList.Add(14);

foreach(int num in arrList)

{

Console.WriteLine(num);

}

}
How to use Dictionary class in Systems.Collections.Generic

Create a Dictionary object and populate it and enumerate it to display key value pairs.

Example if we want to have integer as key and string as value. we can create dictionary object in the following way:

Dictionary<int,string> dictNames =new Dictionary<int,string>();

dicNames.Add(1,”Raj”);

dicNames.Add(3,”Ravi”);

dicNames.Add(5,”Kevin”);

In order to retrieve above value enumerate it i.e use foreach loop
and use KeyValuePair object  as the elements are retrieved as
KeyValuePair objects



foreach(KeyValuePair<int,string> kvpName in dictNames)

Console.WriteLine(kvpName.Key+”  “+kvpName.Value);
list some of the Similarities and Difference between Hashtable and arraylist

Both are used to store objects. mostly In arraylist elements are accessed
using index where as in Hashtable elements are accessed using keys
What is meant by Constraint in Generics

Constraints allow additional contextual information to be added to the type
parameters of generic types. The constraints limit the range of types
that are allowed to be used as type arguments, but at the same time,
they add information about those type parameters.
What is the drawback of arraylist compared with Generic list

In an Arraylist, As Each item is stored as an object, During Sorting and
traversing the list,  it must be typed at runtime, and then compared for sorting/searching wheareas Generic list has all items typed compile
time, which saves a lot of workload during sorting and searching.
How to Serialize the generic types

[Serializable]

public class TestClass<T>
What is Bit Array and properties of Bit Array

The BitArray class manages an array of bit values.
These bit values are boolean in nature,i.e., true (1) or false (0).
Properties

•Count - Gets the number of elements contained in the BitArray.

•IsReadOnly - Gets a value indicating whether the BitArray is read-only.

•Item - Gets or sets the value of the bit at a specific position in the BitArray.

•Length - Gets or sets the number of elements in the BitArray.
what is dictionary? How to use

Dictionary<K,V> is a generic collection that contains data in Key/Value pairs, it
is just like the nongeneric collection Hashtable.
Ex:-Dictionary<string, string> dictionary = new Dictionary<string, string>();
dictionary.Add("Key", "Value"); //Add the specified key and value to the
// dictionary
dictionary.Remove("Key"); //Removes the value with the specified
// key from the dictionary
int count = dictionary.Count; //get the number of the Key/Value pairs
// contained in the dictionary
What are Nested Types in Generics

A type that is nested in a generic type can depend on the type parameters
of the enclosing generic type. The common language runtime considers
nested types to be generic, even if they do not have generic type
parameters of their own. When you create an instance of a nested type,
you must specify type arguments for all enclosing generic types.
what is the advantage of TrimToSize in array list

By this we can decrease the capacity of array List i.e.,we can set capacity to the actual number of elements in the array List.

More C# Interview Questions & Answers here

Found this useful, bookmark this page to the blog or social networking websites. Page copy protected against web site content infringement by Copyscape

 Exclusive Interview Questions and Answers Categories