Saturday, March 6, 2010

C# and Dot Net Interview Questions II

What is XML Schema?
Document Type Declaration(DTD)
determines the name of the root element and contains the document type declarations
Elements
Elements are the main building blocks of both XML and HTML documents.
Examples of HTML elements are “body” and “table”. Examples of XML elements could be “note” and “message”. Elements can contain text, other elements, or be empty. Examples of empty HTML elements are “hr”, “br” and “img”.
Examples:
body text in between
some message in between
———–
Attributes
Attributes provide extra information about elements.
Attributes are always placed inside the starting tag of an element. Attributes always come in name/value pairs. The following “img” element has additional information about a source file:
The name of the element is “img”. The name of the attribute is “src”. The value of the attribute is “computer.gif”. Since the element itself is empty it is closed by a ” /”.
———–
Entities
Entities are variables used to define common text. Entity references are references to entities.
Most of you will know the HTML entity reference: ” “. This “no-breaking-space” entity is used in HTML to insert an extra space in a document. Entities are expanded when a document is parsed by an XML parser.
The following entities are predefined in XML:
Entity References Character
< <
> >
& &
” “
‘ ‘

How can i check whether a dataset is empty or not in C#.net
HasRows property is only for DataReader objects. For DataSet you can check whether it has a DataTable or not .. since the DataSet is a collection of DataTable you can check whether it has loaded a table or not using the following code
DataSet dt=new DataSet();
if (dt.Tables.Count>0) // has tables in it
{
}
else // otherwise it is empty
{
}


Is it possible to inherit a class that has only private constructor?
No.
ex.
Base Class:
/// Summary description for BaseA.
///
public class BaseA
{
private BaseA()
{
//
// TODO: Add constructor logic here
//
}
}
Dervied Class:
///
/// Summary description for Class1.
///
public class DerviedB: BaseA
{
public DerviedB()
{
//
// TODO: Add constructor logic here
//
}
}
Result: DerviedB.cs(10): ‘PrivateAssembly.BaseA.BaseA()’ is inaccessible due to its protection level


How do you choose 1 entry point when C# project has more Main( ) method?
In one .cs file there may be many classes having Main() method. While making the .exe you can define the class name as an entry point
CSC /main:classname filename.cs

The compiler throws an error if XML comments is not well formed
If the XML is not well-formed, a warning is generated and the documentation file will contain a comment saying that an error was encountered.

By declaring a base class function as virtual we allow the function to be overridden in subclasses
The derived class can provide new functionality by overriding the virtual method of the base class.
The method to be called is determined at the run-time depending on the type of the object calling the method, and it does not depend on the type of the variable declared to hold the object. The following example illustrates this point:
Suppose base class B and derived class D provide different implementations of a virtual method V(). Also suppose that there is a non-virtual method NV() of B which is overriden by D.
//In Main(), an object, obj, is declared to be of type B.
B obj;
//An object of D is created for initializing obj
obj = new D;
//Call virtual and non-virtual methods on obj:
obj.V(); //This call would execute D::F() since F() is virtual, and although obj is declared to be of type B, it contains object of type D.
obj.NV(); //This call would execute B::F(), looking at the declaration of obj.
This is the difference between virtual and plain overridable methods. Virtual methods execute slower than non-virtual ones because of run-time resolve of the method to be called. So programmer should be caeful while declaring a method as virtual.

Which of the following can not be declared as virtual
Both A and B are correct choices. Declaring a static function as virtual generates build error. Same with declaring member fields as virtual.
A static function can be called only using class_name.static_function_name() syntax, so there is no run-time resolve depending on the type of object, hence the term virtual does not make a sense in case of static functions.
In case member fields are overriden by a derived class the derived class methods will use the overriden variables by default, so there is no run-time resolve required for fields.


Sealed class can be inherited
sealed classes cannot be inherited as the sealed classes provides full functionality only the classes that have no full functionality can be inherited

Which of the following statements is not true for interfaces
Interfaces must always be declared as public so that they can be implemented or inherited


It is not permitted to declare modifier on the members in an interface definition
A is the correct answer. By default all the members in an Interface definition are public, so there is no need to declare access modifier public. It would be a compile time error otherwise

Interface members can not be declared as
Virtual keyword is meaningful when the derived class is expected to override base class method. Here a class will ‘implement’ a method of an interface, hence virtual is not meaningful for interface methods.
Static keyword indicates that a method or field is common to all instances of a class. For an interface there will not be any instance, hence static is not meaningful.
An interface and all its methods must be declared public for enabling classes to implement them.

No comments:

Post a Comment