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...

  1. When an object is deserialized, does it call default constructor ?
    • Noooooooooo.
  2. 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
  3. 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
Copyright: Hey, if you are copying my questions, dont forget to acknowledge and link it to here

Monday, August 21, 2006

 

Serialization

Two types:

  1. XML Serialization: Do not serialize private fields and read only properties.
  2. 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:

Use a SqlDataReader obtained by calling the ExecuteReader method of the SqlCommand object when:


Friday, July 28, 2006

 

Naming Guide Lines

Pascal case The first letter in the identifier and the first letter of each subsequent concatenated word are capitalized. You can use Pascal case for identifiers of three or more characters. For example:BackColor Camel case The first letter of an identifier is lowercase and the first letter of each subsequent concatenated word is capitalized. For example:backColor Uppercase All letters in the identifier are capitalized. Use this convention only for identifiers that consist of two or fewer letters. For example:System.IO System.Web.UI In C#, mostly Pascal case is used except for method parameter and local veriables. MSDN Naming guidelines

 

How to create Singleton

Singleton is a 'creational pattern' which is used when 'only' one instance of the object is required for the entire client process...Singleton enforces this by creating a private/protected default constructor... here is the whole process Your singleton object should have the following:

class MySingleton{

private static MySingleton obj;

private MySingleton(){};

public static MySigleton GetInstance()

{

if (obj == null) obj = new MySingleton();

return obj;

}

//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

obj1.function1();

obj1.function2();

//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.

}


 

Design Patterns

  1. Singleton
  2. Factory
  3. Abstract
  4. Builder
  5. Prototype
  1. Adapter
  2. Bridge
  3. Composite
  4. Decorator
  5. Facade
  6. Flyweight
  7. Proxy
  1. Chain Of Responsibility
  2. Command
  3. Interpreter
  4. Iterator
  5. Mediator
  6. Memento
  7. Observer
  8. State
  9. Strategy
  10. Template Method
  11. Visitor

Tuesday, July 11, 2006

 

what is the use of 'new' in funciton signature

class BaseClass { public int Add(int a, int b) { return a+b; } } class DerivedClass:BaseClass { public int new Add(int a, int b) { return a+b; } } Note: When the object of DerivedClass is used to access Add function, which of the functions is called ? It would be the one of DerivedClass. This is same even if "new" is used or not. Then what is the use of "new" ? Without "new" complier throws an error of ambiguity. With "new", compiler understands that the programmer knows about the ambiguity and still want the function with the signature to exist in the derived class too.

This page is powered by Blogger. Isn't yours?