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.
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
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.
NOTE: This is objective type question, Please click question title for correct answer.
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?
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.
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
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.
Yes, but they are not accessible. Although they are not visible or accessible via the class interface, they are inherited.
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
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.
Different parameter data types, different number of parameters, different order of parameters.
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.
0; PersonID
m_PersonID; value;
} }
{ { {
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.
void int
Insert(string
firstName,
string
lastName,
int
Calculate(); age);
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");
MessageBox.Show(str);
visit
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.
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.
System.String is immutable. System.StringBuilder was designed with the purpose of having a mutable string where a variety of operations can be performed.
Yes, but they are not accessible. Although they are not visible or accessible via the class interface, they are inherited.
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 ?
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
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 />"; }
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
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
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.
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.