Anda di halaman 1dari 10

What is static constructor?

Posted by: Raja

Static constructor is used to initialize static data members as soon as the class is referenced first time, whereas an instance constructor is used to create an instance of that class with keyword. A static constructor does not take access modifiers or have parameters and can't access any non-static data member of a class.

What is the use of Monitor in C#?


Posted by: Raja

It

provides

mechanism

that

synchronizes

access

to

objects.

The Monitor class controls access to objects by granting a lock for an object to a single thread. Object locks provide the ability to restrict access to a block of code, commonly called a critical section. While a thread owns the lock for an object, no other thread can acquire that lock. You can also use Monitor to ensure that no other thread is allowed to access a section of application code being executed by the lock owner, unless the other thread is executing the code using a different locked object. For more visit http://msdn2.microsoft.com/en-us/library/system.threading.monitor.aspx

What is lock statement in C#?


Posted by: Raja

Lock ensures that one thread does not enter a critical section of code while another thread is in the critical section. If another thread attempts to enter a locked code, it will wait, block, until the object is released.

Is overriding of a function possible in the same class?


Posted by: Poster

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

How to loop through all rows of the DataTable?


Posted by: Raja

You can do this in more than one way but ForEach loop is much better than any other way in terms of cleanliness of the code or performance. ForEach loop
foreach (DataRow row in dTable.Rows) { yourvariable = row["ColumnName"].ToString(); }

For loop
for (int j = 0; j< dTable.Rows.Count; j++) { yourvariable = dTable.Rows[j]["ColumnName"].ToString()l }

What is an Array?
Posted by: Raja

An array is a collection of related instance either value or reference types. Array posses an immutable structure in which the number of dimensions and size of the array are fixed at instantiation. C# Supports Single, Mult dimensional and Jagged Array.

Single Dimensional Array: it is sometimes called vector array consists of single row. Multi-Dimensional Array: are rectangular & consists of rows and columns.

Jagged Array: also consists of rows & columns but in irregular shaped (like row 1 has 3 column and row 2 has 5 column)

What is an ArrayList?
Posted by: Raja

ArrayList is a dynamic array. Elements can be added & removed from an arraylist at the runtime. In this elements are not automatically sorted.

What is BitArray?
Posted by: Raja

The BitArray collection is a composite of bit values. It stores 1 or 0 where 1 is true and 0 is false. This collection provides an efficient means of storing and retrieving bit values.

What is HashTable?
Posted by: Raja

A Hashtable is a collection of key-value pairs. Entries in this are instance of DictionaryEntry type. It implements IDictionary, ISerilizable, IDeserializable collback interface.

What is Queue?

Posted by: Raja

This is a collection that abstracts FIFO (First In First Out) data structure. The initial capacity is 32 elements. It is ideal for messaging components.

What is Stack?
Posted by: Raja

This is a collection that abstracts LIFO (Last In First Out) data structure in which initial capacity is 32.

What is SortedList?
Posted by: Raja

This is a collection and it is a combination of key/value entries and an ArrayList collection. Where the collection is sorted by key.

What is Delegates?
Posted by: Raja

A delegate in C# allows you to pass method of one class to objects of other class that can call these methods. OR A delegate is an object that holds the reference to a method.

In C++ it is called function pointer.

What is a collection?
Posted by: Poster

A collection serves as a container for instances of other classes. All classes implement ICollection interface which intern implement IEnumerable interface.

What is reflection?
Posted by: Poster

Reflection is the ability to find the information about types contained in an assembly at runtime. OR Reflection is the ability to find out information about objects, the application details (assemblies), its metadata at run-time. Edited: See the example: http://www.dotnetfunda.com/articles/article132.aspx

How is the DLL Hell problem solved in .NET?


Posted by: Poster

Assembly versioning allows the application to specify not only the library it needs to run (which was available under Win32), but also the version of the assembly.

Are private class-level variables inherited?


Posted by: Poster

Yes, but they are not accessible. Although they are not visible or accessible via the class interface, they are inherited.

Whats the difference between the System.Array.CopyTo() and System.Array.Clone()?


Posted by: Poster

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?
Posted by: Poster

By calling Array.Sort() and then Array.Reverse() methods.

What class is underneath the SortedList class?


Posted by: Poster

A sorted HashTable.

Can you prevent your class from being inherited by another class?
Posted by: Raja

Yes. The keyword sealed will prevent the class from being inherited.

Can you allow a class to be inherited, but prevent the method from being over-ridden?
Posted by: Raja

Yes. Just leave the class public and make the method sealed.

What are the different ways a method can be overloaded?


Posted by: Raja

Different parameter data types, different number of parameters, different order of parameters.

What is the use of CommandBehavior.CloseConnection?


Posted by: Raja

We

can

use

pass =

it

with

ExecuteReader

method

of

Command

object

like

reader

cmd.ExecuteReader(CommandBehavior.CloseConnection);

This will make sure that when we are calling reader.Close() the associated connection object will also be closed.

How to declare a property in a class?


Posted by: SheoNarayan

int public { get set }

m_PersonID int { { return m_PersonID =

0; PersonID

m_PersonID; value;

} }

How to declare a property in an Interface?


Posted by: SheoNarayan

DateTime int string

DateOfBirth Age FirstName

{ { {

get;set;} get;set;} get;set;}

As this is an Interface, so no implementation required only definition of properties are required. Implementation of these properties will be written into the class inherting this interface.

How to declare methods into an Interface


Posted by: SheoNarayan

void int

Insert(string

firstName,

string

lastName,

int

Calculate(); age);

Interface doesn't contain implementation so methods implementation will be written into

class inherting this interface.

How to load assembly from GAC?


Posted by: SheoNarayan

Lets say you have to load the assembly from GAC on button click event then you should write following method.
protected void btn_Click(object sender, EventArgs e)

AssemblyName Culture=neutral,

asm

new

AssemblyName("ClassLibrary1,

Version=1.1.0.0,

PublicKeyToken=fbc28d9ca2fc8db5");

Assembly al = Assembly.Load(asm);

Type t = al.GetType("ClassLibrary1.Class1");

MethodInfo m = t.GetMethod("Method1");

str = "reflection - " + (string)m.Invoke(null, null);

MessageBox.Show(str);

For more http://www.infosysblogs.com/microsoft/2007/04/loading_multiple_versions_of_s.html

visit

Difference Between dispose and finalize method?

Posted by: Majith

Dispose For

is

method

for

realse

from

the

memory

for

an

object. eg:

<object>.Dispose. Finalize is used to fire when the object is going to realize the memory.We can set a alert message to says that this object is going to dispose.

What does the term immutable mean?


Posted by: Majith

The data value may not be changed. Note: The variable value may be changed, but the original immutable data value was discarded and a new data value was created in memory.

Whats the difference between System.String and System.Text.StringBuilder classes?


Posted by: Majith

System.String is immutable. System.StringBuilder was designed with the purpose of having a mutable string where a variety of operations can be performed.

Are private class-level variables inherited?


Posted by: Majith

Yes, but they are not accessible. Although they are not visible or accessible via the class interface, they are inherited.

What class is underneath the SortedList class?


Posted by: Majith

A sorted HashTable

What happens if you inherit multiple interfaces and they have conflicting method names?
Posted by: Majith

Its up to you to implement the method inside your own class, so implementation is left entirely up to you. This might cause a problem on a higher-level scale if similarly named methods from different interfaces expect different data, but as far as compile r cares youre okay. To Do: Investigate

Types of Errors ?

Posted by: Majith

Configuration Parser Compilation Run-Time Errors

Errors Errors Errors

Difference between classes and structures?


Posted by: Majith

struct

is

value

type

and

class

is

reference

type.

When we instantiate a class, memory will be allocated on the heap and when struct gets initiated it gets memory on the stack. Classes can have explicit parameter less constructors. But structs dosn't have this. Classes support inheritance. No inheritance for structs.

A struct cannot inherit from another struct or class, and it cannot be the base of a class. Like classes, structures can implement interfaces.

How to convert a sentence into Title Case (Capitalize first character of every word)?
Posted by: Raja

Use ToTitleCase method.


System.Globalization.CultureInfo.CurrentCulture.TextInfo.ToTitleCase(&quot;dotnetfunda .com is a very good website&quot;);

The output will be "Dotnetfunda.Com Is A Very Good Website"

How to sort an array into descending order?


Posted by: Raja

First Eg.

sort

the

array

using

Array.Sort

and

then

use

Array.Reverse

int[] number = new int[] {6, 4, 7}; Array.Sort(number); // sort in ascending order foreach (int i in number) { lblMessage.Text += i + " <br />";

} // reverse ie descending order Array.Reverse(number); lblMessage.Text += "<hr />"; foreach (int i in number) { lblMessage.Text += i + " <br />"; }

How to read entire stream contents?


Posted by: Raja

If you have a stream object (any of the stream like StreamReader, MemoryStream, FileStream) and you want to show its content, write following code.

// here theStream is the stream object while (myStream.Position != myStream.Length) { Console.WriteLine("{0:x2}", myStream.ReadByte()); }

Write a single line of code to read the entire content of the text file.
Posted by: Raja

User

following

code

string strContent = System.IO.File.ReadAllText(Server.MapPath("~/MyTextFile.txt"));

Write a single line of code to create a text file and write contents into it.
Posted by: Raja

Use

following

code

System.IO.File.WriteAllText(@"c:\MyTextFile.txt", "MyContents");

What is the best way to add items from an Array into ArrayList?
Posted by: Raja

Use AddRange method of the ArrayList.


string[] arr = new string[] { "ram", "shyam", "mohan" }; ArrayList arrList = new ArrayList(); arrList.AddRange(arr);

You pass a value-type variable into a procedure as an argument. The procedure changes the variable; however, when the procedure returns, the variable has not changed. What happened? (Choose one.)
Posted by: Raja

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

Which of the following is NOT Value type variable?


Posted by: Raja

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

You need to create a simple class or structure that contains only value types. You must create the class or structure so that it runs as efficiently as possible. You must be able to pass the class or structure to a procedure without concern that the procedure will modify it. Which of the following should you create?
Posted by: Raja

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

Anda mungkin juga menyukai