Tuesday, August 21, 2007
C# interview questions
Note: the answers are blanked out in white color. Just use your mouse and select the bullet point below the mouse, you can see the answer.
These are my own questions and not copied...
- When an object is deserialized, does it call default constructor ?
- What is the interface that a class needs to implement inorder for it to be able to be bound to controls.
- For Win Forms: No interface required. For web forms:IBindingList
- You can not sign an assembly with strong name after it is created. True or False ?
- True. You can sign an assembly with a strong name only when you create it. Also., all assemblies that reference stong named assembly also have to have strong names, so that the security of the strongly named assembly is not compromised
Monday, August 21, 2006
- XML Serialization: Do not serialize private fields and read only properties.
- Formatted Serialization: Serializes every thing. Must be marked with [Serializable]. Optinally implement ISerializable interface. Two types:
- Binary Formatter
- SOAP Formatter
Wednesday, August 09, 2006
SqlDataAdapter (Dataset) vs SqlDataReader
When to use SqlDataAdapter? and When to use SqlDataReader ?
If you use a SqlDataAdapter to generate a DataSet or DataTable, note the following:
- You do not need to explicitly open or close the database connection. The SqlDataAdapter Fill method opens the database connection and then closes the connection before it returns. If the connection is already open, Fill leaves the connection open.
- If you require the connection for other purposes, consider opening it prior to calling the Fill method. You can thus avoid unnecessary open/close operations and gain a performance benefit.
- Although you can repeatedly use the same SqlCommand object to execute the same command multiple times, do not reuse the same SqlCommand object to execute different commands. For a code sample that shows how to use a SqlDataAdapter to populate a DataSet or DataTable, see How to Use a SqlDataAdapter to Retrieve Multiple Rows in the appendix. Using a SqlDataReader
Use a SqlDataReader obtained by calling the ExecuteReader method of the SqlCommand object when:
- You are dealing with large volumes of data—too much to maintain in a single cache.
- You want to reduce the memory footprint of your application.
- You want to avoid the object creation overhead associated with the DataSet.
- You want to perform data binding with a control that supports a data source that implements IEnumerable.
- You wish to streamline and optimize your data access.
- You are reading rows containing binary large object (BLOB) columns. You can use the SqlDataReader to pull BLOB data in manageable chunks from the database, instead of pulling all of it at once. For more details about handling BLOB data, see the Handling BLOBs section in this document.
Friday, July 28, 2006
Naming Guide Lines
How to create Singleton
- Private static variable which holds the instance of the same class
- Private Constructor with no code in it
- Public static method that return the private static variable declared in the first step. This method should check if the variable is null, if so, create a new instance, assign it to the variable and return the variable.
private static MySingleton obj;
public static MySigleton GetInstance()
if (obj == null) obj = new MySingleton();
//all other functions go here.. these functions have to be static
From the client, a sigleton is used like the following:
public static void main()
//Since MySingleton has a private constructor, it can not be instantiated like a regular class. The
following code throws an error
//MySingleton 0 = new MySingleton(); //throws errror
MySingleton obj1 = MySigleton.GetInstance(); // since this is first call, an object gets created in the GetInstance function and gets added to the class global variable of obj
//Now later when the user tried to create a new object of MySigleton, the same object is returned
MySingleton obj2 = MySigleton.GetInstance(); //returns the same object created in the first call.
- Creational Patterns
- Structural Patterns
- Behavioral Pattern
- Chain Of Responsibility
- Template Method