Sunday, June 29, 2008

Web Service Questions

1. What is the transport protocol you use to call a Web service?
SOAP (Simple Object Access Protocol) is the preferred protocol.

2. True or False: A Web service can only be written in .NET?
False
3. What does WSDL stand for?
Web Services Description Language.

4. Where on the Internet would you look for Web services?
http://www.uddi.org/
5. True or False: To test a Web service you must create a Windows application or Web application to consume this service?
False, the web service comes with a test page and it provides HTTP-GET method to test.

Saturday, June 28, 2008

AJAX

AJAX
1Q):-What is AJAX?

Ans):-Ajax stands for Asynchronous Javascript & XML. It is a web technology through which a postback from a client (browser) to the server goes partially, which means that instead of a complete postback, a partial postback is triggered by the Javascript XmlHttpRequest object. In such a scenario, web-application users won't be able to view the complete postback progress bar shown by the browser. In an AJAX environment, it is Javascript that starts the communication with the web server.

Ajax technology in a website may be implemented by using plain Javascript and XML. Code in such a scenario may tend to look little complex, for which the AJAX Framework in .NET can be embedded in ASP.NET web applications.

In addition to XML & Javascript, AJAX is also based on DOM - the Document Object Model technology of browsers through which objects of the browser can be accessed through the memory heap using their address.

JSON - Javascript Object Notation is also one of the formats used in AJAX, besides XML.
So basically, in an AJAX-based web application, the complete page does not need to reload, and only the objects in context of ajaxification are reloaded.
Ajax technology avoids the browser flickering.

2Q):-Can Ajax be implemented in browsers that do not support the XmlHttpRequest object?

Ans):-Yes. This is possible using remote scripts.

3Q):-Can AJAX technology work on web servers other than IIS?

Ans):-Yes, AJAX is a technology independent of web server the web application is hosted on. Ajax is a client (browser) technology.

4Q):-Which browsers support the XmlHttpRequest object?

Ans):-Internet Explorer 5.0+, Safari 1.2, Mozilla 1.0/Firefox, Opera 8.0 +, Netscape 7

5Q):-How to we create an XmlHttpRequest object for Internet Explorer? How is this different for other browsers?

Ans):-For Internet Explorer, an ActiveXObject is used for declaring an XmlHttpRequest object in Javascript.
//Code as below for IE:

xmlHttpObject = new ActiveXObject("Msxml2.XMLHTTP");

//For Other browsers, code as below:

xmlHttpObject = new XMLHttpRequest();
Note that XmlHttpObject used above is simply a variable that holds the XmlHttpRequest object for the respective browsers.




6Q):-What are the properties of the XmlHttpRequest object? What are the different types of readyStates in Ajax?

Ans):-

i)onreadyStateChange - This function is used to process the reply from the web server.

ii)readyState - This property holds the response status of the web server. There are 5 states:

0 - request not yet initialized

1 - request now set

2 - request sent

3 - request processing

4 - request completes

iii)responseText - Has the data sent back by the web server

Code snippet below shows an example how these there properties are used to implement ajax :


xmlHttpObject.onreadystatechange=function()
{
if(xmlHttpObject.readyState==4)
{
document.Form1.time.value=xmlHttpObject.responseText;
}
}

7Q):- What is the ASP.NET Ajax Framework? What versions have been released so far?

Ans):-ASP.NET AJAX is a free framework to implement Ajax in asp.net web applications, for quickly creating efficient and interactive Web applications that work across all popular browsers.

The Ajax Framework is powered with:-
1 -Reusable Ajax Controls

2 -Support for all modern browsers

3 -Access remote services and data from the browser without tons of complicated script.

Versions of Ajax release:-
1 -ASP.NET Ajax Framework 1.0 (earlier release to this was called the Atlas)
2 -ASP.NET Ajax Framework 1.0 was available as a separate download for ASP.NET 2.0

8Q):-What are Ajax Extensions?

Ans):-The ASP.NET Ajax Extensions are set of Ajax-based controls that work in ASP.NET 2 (or above) based applications.

Ofcourse,they also need the Ajax runtime which is actually the Ajax Framework 1.0.

ASP.NET Ajax Extensions 1.0 have to be downloaded to run with ASP.NET 2.0

The new ASP.NET 3.5 Framework comes with the Ajax Library 3.5 (containing the Ajax Extensions 3.5).
So in order to use the latest Ajax, simply download .NET 3.5 Framework.

Summary :
ASP.NET Ajax Extensions 1.0 -> For ASP.NET 2.0
ASP.NET Ajax Extensions 3.5 -> For ASP.NET 3.5

9Q):-What is the ASP.NET Control Toolkit?

Ans):-Besides the Ajax Framework (which is the Ajax engine) and Ajax Extensions (which contain the default Ajax controls), there is a toolkit called the Ajax Control Toolkit available for use & download (for free). This is a collection of rich featured, highly interactive controls, created as a joint venture between Microsoft & the Developer Community.

10Q):-What is Dojo?

Ans):-Dojo is a third-party javascript toolkit for creating rich featured applications. Dojo is an Open Source DHTML toolkit written in JavaScript. It builds on several contributed code bases (nWidgets, Burstlib, f(m)), which is why we refer to it sometimes as a "unified" toolkit. Dojo aims to solve some long-standing historical problems with DHTML which prevented mass adoption of dynamic web application development.

For more on Dojo, check this link: Click Here

11Q):-How to handle multiple or concurrent requests in Ajax?

Ans):-For concurrent requests, declare separate XmlHttpRequest objects for each request. For example, for request to get data from an SQL table1, use something like this...
xmlHttpObject
1.Onreadystatechange = functionfromTable1();
and to get data from another table (say table2) at the same time, use
xmlHttpObject
2.Onreadystatechange = functionfromTable2();
Ofcourse, the XmlHttpObject needs to be opened & parameters passed too, like as shown below...
xmlHTTPObject
1.open("GET","http://"localhost// " + "Website1/Default1.aspx" true);

Note that the last parameter "true" used above means that processing shall carry on without waiting for any response from the web server. If it is false, the function shall wait for a response.

12Q):-How to create an AJAX website using Visual Studio?

Ans):-Using Visual Studio Web Developer Express 2005 & versions above it, Ajax based applications may easily be created. Note that the Ajax Framework & Ajax Extensions should be installed (In case of VS 2005). If using Visual Studio 2008 Web Developer Express or above, Ajax comes along with it (so no need of a separate installation).

Steps:
Start Visual Studio, Click on File -> New Website -> Under Visual Studio Installed templates -> Select ASP.NET Ajax-Enabled Site. Enter a location & select OK.

13Q):-What is the role of ScriptManager in Ajax?

Ans):-ScriptManager class is the heart of ASP.NET Ajax. Before elaborating more on ScriptManager, note that ScriptManager is class and a control (both) in Ajax.

The ScriptManager class in ASP.NET manages Ajax Script Libraries, partial page rendering functionality and client proxy class generation for web applications and services. By saying client proxy class, this means an instance of the Ajax runtime is created on the browser.

This class is defined in the System.Web.Extensions.dll.
You will find this DLL in your system's Global Assembly Cache at C:\Windows\Assembly (For XP)

The ScriptManager control (that we may drag on a web form) is actually an instance of the ScriptManager class that we put on a web page.
The ScriptManager manages all the ASP.NET Ajax controls on a web page. Following tasks are taken care by the ScriptManager class:

1 -Managing all resources (all objects/controls) on a web page
2 -Managing partial page updates
3 -Download Ajax Script Library to the client (means to the browser).
This needs to happen so that Ajax engine is accessible to the browsers javascript code.
4 -Interacting with UpdatePanel Control, UpdateProgress Control.
5 -Register script (using RegisterClientScriptBlock)
6 -Information whether Release OR Debug script is sent to the browser
7 -Providing access to Web service methods from the script by registering Web services with the ScriptManager control
8 -Providing access to ASP.NET authentication, role, and profile application services from client script after registering these services with the ScriptManager control
9 -Enable culture specific display of clientside script.
10 -Register server controls that implement IExtenderControl and IScriptControl interfaces.

ScriptManager class' EnablePartialRendering property is true by default.

14Q):-Can we override the EnablePartialRendering property of the ScriptManager class?

Ans):-Yes. But this has to be done before the init event of the page (or during runtime after the page has already loaded). Otherwise an InvalidOperationException will be thrown.

15Q):-How to use multiple ScriptManager controls in a web page?

Ans):-No. It is not possible to use multiple ScriptManager control in a web page. In fact, any such requirement never comes in because a single ScriptManager control is enough to handle the objects of a web page.

16Q):-Whats the difference between RegisterClientScriptBlock, RegisterClientScriptInclude and RegisterClientScriptResource?

Ans):-For all three, a script element is rendered after the opening form tag. Following are the differences:

1 -RegisterClientScriptBlock - The script is specified as a string parameter.
2 -RegisterClientScriptInclude - The script content is specified by setting the src attribute to a URL that points to a script file.
3 -RegisterClientScriptResource - The script content is specified with a resource name in an assembly. The src attribute is automatically populated with a URL by a call to an HTTP handler that retrieves the named script from the assembly.

17Q):-What are type/key pairs in client script registration? Can there be 2 scripts with the same type/key pair name?

Ans):-When a script is registered by the ScriptManager class, a type/key pair is created to uniquely identify the script.

For identification purposes, the type/key pair name is always unique for dentifying a script. Hence, there may be no duplication in type/key pair names.

18Q):-What is an UpdatePanel Control?

Ans):-An UpdatePanel control is a holder for server side controls that need to be partial postbacked in an ajax cycle. All controls residing inside the UpdatePanel will be partial postbacked. Below is a small example of using an UpdatePanel.

As you see here after running the snippet above, there wont be a full postback exhibited by the web page. Upon clicking the button, the postback shall be partial. This means that contents outside the UpdatePanel wont be posted back to the web server. Only the contents within the UpdatePanel are refreshed.

19Q):-What are the modes of updation in an UpdatePanel? What are Triggers of an UpdatePanel?

Ans):-An UpdatePanel has a property called UpdateMode. There are two possible values for this property: 1) Always 2) Conditional

If the UpdateMode property is set to "Always", the UpdatePanel control’s content is updated on each postback that starts from anywhere on the webpage. This also includes asynchronous postbacks from controls that are inside other UpdatePanel controls, and postbacks from controls which are not inside UpdatePanel controls.

If the UpdateMode property is set to Conditional, the UpdatePanel control’s content is updated when one of the following is true:

1 -When the postback is caused by a trigger for that UpdatePanel control.

2 -When you explicitly call the UpdatePanel control's Update() method.

3 -When the UpdatePanel control is nested inside another UpdatePanel control and the parent panel is updated.

When the ChildrenAsTriggers property is set to true and any child control of the UpdatePanel control causes a postback. Child controls of nested UpdatePanel controls do not cause an update to the outer UpdatePanel control unless they are explicitly defined as triggers for the parent panel.

Controls defined inside a node have the capability to update the contents of an UpdatePanel.

If the ChildrenAsTriggers property is set to false and the UpdateMode property is set to Always, an exception is thrown. The ChildrenAsTriggers property is intended to be used only when the UpdateMode property is set to Conditional.



20Q):-How to control how long an Ajax request may last?

Ans):-Use the ScriptManager's AsyncPostBackTimeout Property.

For example, if you want to debug a web page but you get an error that the page request has timed out, you may set

where the value specified is in seconds.

21Q):-What is ASP.NET Futures?

Ans):-ASP.NET AJAX Futures

The new release includes support for managing browser history (Back button support), selecting elements by CSS selectors or classes, and information on accessing “Astoria” Web data services. The Futures (July 2007) release adds:

History support for the Safari browser, inclusion of “titles”, encoding and encrypting of server-side history state and the ability to handle history in the client without a server requirement.

CSS Selectors APIs have been modified to be applicable to W3C recommendations.

A script resource extraction tool that allows you to create script files on disk that originate from embedded resources in assemblies. Important: this version of the browser history feature is now outdated and should not be used. Instead, please download the ASP.NET 3.5 Extensions Preview, which contains the new version.

For More: Click Here

22Q):-What are limitations of Ajax?

Ans):-
1)An Ajax Web Application tends to confused end users if the network bandwidth is slow, because there is no full postback running. However, this confusion may be eliminated by using an UpdateProgress control in tandem.
2)Distributed applications running Ajax will need a central mechanism for communicating with each other

23Q):-How to make sure that contents of an UpdatePanel update only when a partial postback takes place (and not on a full postback)?

Ans):-Make use of ScriptManager.IsInAsyncPostBack property (returns a boolean value)

24Q):-How to trigger a postback on an UpdatePanel from Javascript?

Ans):-Call the __doPostBack function. ASP.NET runtime always creates a javascript function named __doPostBack(eventTarget, eventArgument) when the web page is rendered.
A control ID may be passed here to specifically invoke updation of the UpdatePanel.

25Q):-Which request is better with AJAX, Get or Post?

Ans):-AJAX requests should use an HTTP GET request while retrieving data where the data does not change for a given URL requested. An HTTP POST should be used when state is updated on the server. This is in line with HTTP idempotency recommendations and is highly recommended for a consistent web application architecture.

Monday, June 16, 2008

Shadowing

Shadowing:
When two elements in a program have the same name,one of them can hide and shadow the other one.So in such cases the element which shadowed the main element is referenced.

For example:

public class ClsParent
public x as Integer
End class
public class ClsShadowedParent
inherits ClsParent
public shadow x as string
End class

Different accessibility levels defined in .NET

public : Access is not restricted.

protected : Access is limited to the containing class or types derived from the containing class.

internal : Access is limited to the current assembly.

protected internal : Access is limited to the current assembly or types derived from the containing class.

private : Access is limited to the containing type. Outside classed can't access private type

Only one access modifier is allowed for a member or type, except when using the protected internal combination

Sunday, June 15, 2008

Inheritance and polymorphism

Inheritance
Classes can inherit from another class. This is accomplished by putting a colon after the class name when declaring the class, and naming the class to inherit from—the base class—after the colon, as followspublic
class A{
public A() { }
}
public class B : A
{ public B() { }
}

Polymorphism

Polymorphism means same operation may behave differently on different classes.
Example of Compile Time Polymorphism: Method Overloading
Example of Run Time Polymorphism: Method Overriding

Poly means many and morph means form. Thus, polymorphism refers to being able to use many forms of a type without regard to the details.
Polymorphism ->one name, many form

Wednesday, June 4, 2008

Object Oriented Programming (OOPS) Languages and asp.net

What is polymorphism in Object Oriented Programming (OOPS) Languages?
In object-oriented programming, polymorphism is a generic term that means 'many shapes'. (from the Greek meaning "having multiple forms"). Polymorphism is briefly described as "one interface, many implementations." polymorphism is a characteristic of being able to assign a different meaning or usage to something in different contexts - specifically, to allow an entity such as a variable, a function, or an object to have more than one form. There are two types of polymorphism one is compile time polymorphism and the other is run time polymorphism. Compile time polymorphism is functions and operators overloading. Runtime time polymorphism is done using inheritance and virtual functions. Here are some ways how we implement polymorphism in Object Oriented programming languages Interface and abstract methodsLike in C# or JAVA different classes implement a common interface in different ways; is an example of Runtime polymorphism. The interface defines the abstract member functions (no implementation). In class that implement the interface; we define body of those abstract members according to the requirement. Means single definition in interface but multiple implementation in child classes. Virtual member functionsUsing virtual member functions in an inheritance hierarchy allows run-time selection of the appropriate member function. A virtual function is a member function of the base class and which is redefined by the derived class. Such functions can have different implementations that are invoked by a run-time determination of the subtype (virtual method invocation, dynamic binding).

Function Overloading Polymorphism means that functions assume different forms at different times. In case of compile time it is called function overloading. Two or more functions can have same name but their parameter list should be different either in terms of parameters or their data types. The functions which differ only in their return types cannot be overloaded. The compiler will select the right function depending on the type of parameters passed. Operator OverloadingIn polymorphism operators can also be overloaded (Compile time polymorphism). Operators can be overloaded in order to perform special functions with respect to the class. With the help of operator overloading standard operations such as + , - , * , etc can be applied on the objects of the class.

What is a Virtual Functions in class?
A virtual function is a member function of the base class and which is redefined by the derived class. When a derived class inherits the class containing the virtual function, it has ability to redefine the virtual functions. A virtual function has a different functionality in the derived class according to the requirement. The virtual function within the base class provides the form of the interface to the function. Virtual function implements the philosophy of one interface and multiple methods (polymorphism).
The virtual functions are resolved at the run time. This is called dynamic binding. The functions which are not virtual are resolved at compile time which is called static binding. A virtual function is created using the keyword virtual which precedes the name of the function.


What is Encapsulation in Object Oriented Programming (OOPS) Languages?
Encapsulation is the procedure of covering up of data and functions into a single unit. Encapsulation (also information hiding) consists of separating the external aspects of an object which are accessible to other objects, from the internal implementation details of the object, which are hidden from other objects. A process, encapsulation means the act of enclosing one or more items within a (physical or logical) container (Class). Object-oriented programming is based on encapsulation. When an objects state and behavior are kept together, they are encapsulated. That is, the data that represents the state of the object and the methods (Functions and Subs) that manipulate that data are stored together as a cohesive unit. The object takes requests from other client objects, but does not expose its the details of its data or code to them. The object alone is responsible for its own state, exposing public messages for clients, and declaring private methods that make up its implementation. The client depends on the (hopefully) simple public interface, and does not know about or depend on the details of the implementation. For example, a HashTable object will take get() and set() requests from other objects, but does not expose its internal hash table data structures or the code strategies that it uses.
Explain the advantages of Encapsulation in Object Oriented Programming Languages.
Benefits of Encapsulation in oops: Encapsulation makes it possible to separate an objects implementation from its behavior to restrict access to its internal data. This restriction allows certain details of an objects behavior to be hidden. It allows us to create a "black box" and protects an objects internal state from corruption by its clients. Encapsulation is a technique for minimizing interdependencies among modules by defining a strict external interface. This way, internal coding can be changed without affecting the interface, so long as the new implementation supports the same (or upwards compatible) external interface. So encapsulation prevents a program from becoming so interdependent that a small change has massive ripple effects. The implementation of an object can be changed without affecting the application that uses it for: Improving performance, fix a bug, consolidate code or for porting.
Limitations and Restrictions of Interface
The essential idea to remember is that an interface never contains any implementation. The following restrictions and imitations are natural consequences of this: You're not allowed any fields in an interface, not even static ones. A field is an implementation of an object attribute. You're not allowed any constructors in an interface. A constructor contains the statements used to initialize the fields in an object, and an interface does not contain any fields! You're not allowed a destructor in an interface. A destructor contains the statements used to destroy an object instance. You cannot supply an access modifier. All methods in an interface are implicitly public. You cannot nest any types (enums, structs, classes, interfaces, or delegates) inside an interface.

You're not allowed to inherit an interface from a struct or a class. Structs and classes contain implementation; if an interface were allowed to inherit from either, it would be inheriting some implementation
What is an Object?
An object is an instance of a class. It can be uniquely identified by its name and it defines a state which is represented by the values of its attributes at a particular time. An object can be considered a "thing" that can perform a set of activities. The set of activities that the object performs defines the object's behavior.
The state of the object changes according to the methods which are applied to it. We refer to these possible sequences of state changes as the behavior of the object. So the behavior of an object is defined by the set of methods which can be applied on it. Objects can communicate by passing messages to each other.
What is inheritance?
Inheritance is the mechanism which allows a class A to inherit properties of a class B. We say "A inherits from B''. Objects of class A thus have access to attributes and methods of class B without the need to redefine them. If class A inherits from class B, then B is called superclass of A. A is called subclass of B. Objects of a subclass can be used where objects of the corresponding superclass are expected. This is due to the fact that objects of the subclass share the same behavior as objects of the superclass.
However, subclasses are not limited to the state and behaviors provided to them by their superclass. Subclasses can add variables and methods to the ones they inherit from the superclass. In the literature you may also find other terms for "superclass" and "subclass". Superclasses are also called parent classes or base classes. Subclasses may also be called child classes or just derived classes. Inheritance Example Like a car, truck or motorcycles have certain common characteristics- they all have wheels, engines and brakes. Hence they all could be represented by a common class Vehicle which encompasses all those attributes and methods that are common to all types of vehicles. However they each have their own unique attributes; car has 4 wheels and is smaller is size to a truck; whereas a motorcycle has 2 wheels. Thus we see a parent-child type of relationship here where the Car, Truck or Motorcycle can inherit certain Characteristics from the parent Vehicle; at the same time having their own unique attributes. This forms the basis of inheritance; Vehicle is the Parent, Super or the Base class. Car, Truck and Motorcycle become the Child, Sub or the Derived class.
Explain some characteristics of inheritance.
A class inherits the members of its direct base class. Inheritance means that a class implicitly contains all members of its direct base class, except for the constructors and destructors of the base class. Some important aspects of inheritance are: Inheritance is transitive. If C is derived from B, and B is derived from A, then C inherits the members declared in B as well as the members declared in A.
A derived class extends its direct base class. A derived class can add new members to those it inherits, but it cannot remove the definition of an inherited member. Constructors and destructors are not inherited, but all other members are, regardless of their declared accessibility. However, depending on their declared accessibility, inherited members might not be accessible in a derived class. A derived class can hide inherited members by declaring new members with the same name or signature. Note however that hiding an inherited member does not remove that member; it merely makes that member inaccessible in the derived class. An instance of a class contains a set of all instance fields declared in the class and its base classes, and an implicit conversion exists from a derived class type to any of its base class types. Thus, a reference to an instance of some derived class can be treated as a reference to an instance of any of its base classes. A class can declare virtual methods, properties, and indexers, and derived classes can override the implementation of these function members. This enables classes to exhibit polymorphic behavior wherein the actions performed by a function member invocation varies depending on the run-time type of the instance through which that function member is invoked.
What is an Interface in Microsoft.Net?
An Interface is a reference type and it contains only abstract members. Interface's members can be Events, Methods, Properties and Indexers. But the interface contains only declaration for its members. Any implementation must be placed in class that realizes them. The interface can't contain constants, data fields, constructors, destructors and static members. All the member declarations inside interface are implicitly public.
Implementing an interface allows a class to become more formal about the behavior it promises to provide. Interfaces form a contract between the class and the outside world, and this contract is enforced at build time by the compiler. If your class claims to implement an interface, all methods defined by that interface must appear in its source code before the class will successfully compile.

What is the difference between abstract class and interface?
We use abstract class and interface where two or more entities do same type of work but in different ways. Means the way of functioning is not clear while defining abstract class or interface. When functionality of each task is not clear then we define interface. If functionality of some task is clear to us but there exist some functions whose functionality differs object by object then we declare abstract class.
We can not make instance of Abstract Class as well as Interface. They only allow other classes to inherit from them. And abstract functions must be overridden by the implemented classes. Here are some differences in abstract class and interface. An interface cannot provide code of any method or property, just the signature. We dont need to put abstract and public keyword. All the methods and properties defined in Interface are by default public and abstract. An abstract class can provide complete code of methods but there must exist a method or property without body. A class can implement several interfaces but can inherit only one abstract class. Means multiple inheritance is possible in .Net through Interfaces.
What is a static class?
We can declare a static class. We use static class when there is no data or behavior in the class that depends on object identity. A static class can have only static members. We can not create instances of a static class using the new keyword. .NET Framework common language runtime (CLR) loads Static classes automatically when the program or namespace containing the class is loaded.
Here are some more features of static class:
Static classes only contain static members.
Static classes can not be instantiated. They cannot contain Instance Constructors
Static classes are sealed.
What is static member of class?
A static member belongs to the class rather than to the instances of the class. In C# data fields, member functions, properties and events can be declared static. When any instances of the class are created, they cannot be used to access the static member.
To access a static class member, use the name of the class instead of an instance variable
Static methods and Static properties can only access static fields and static events. Like: int i = Car.GetWheels; Here Car is class name and GetWheels is static property. Static members are often used to represent data or calculations that do not change in response to object state.

What is a field?
A field is a variable that is associated with a class or struct, or an instance of a class or struct. A field declared with the static modifier defines a static variable, and a field declared without this modifier defines an instance variable. A static field is associated with a type, whereas an instance variable is associated with an instance.

What is the difference between value parameter and reference parameter?
A value parameter is used for "in" parameter passing, in which the value of an argument is passed into a method, and modifications of the parameter do not impact the original argument. A value parameter refers to its own variable, one that is distinct from the corresponding argument. This variable is initialized by copying the value of the corresponding argument.
A reference parameter is used for "by reference" parameter passing, in which the parameter acts as an alias for a caller-provided argument. A reference parameter does not itself define a variable, but rather refers to the variable of the corresponding argument. Modifications of a reference parameter impact the corresponding argument.

What is the use of parameter array?
A parameter array enables a many-to-one relationship: many arguments can be represented by a single parameter array. In other words, parameter arrays enable variable length argument lists.
A parameter array is declared with a params modifier in C#. There can be only one parameter array for a given method, and it must always be the last parameter specified. The type of a parameter array is always a single dimensional array type. A caller can either pass a single argument of this array type, or any number of arguments of the element type of this array type.
What is the difference between reference parameter and output parameter?
Modifications of a reference parameter and output parameter impact the corresponding argument. So an output parameter is similar to a reference parameter, except that the initial value of the caller-provided argument is unimportant.
In C# a reference parameter is declared with a ref modifier but an output parameter is declared with an out modifier.
What is a constant?
A constant is a class member that represents a constant value: a value that can be computed at compile-time. Constants are permitted to depend on other constants within the same program as long as there are no circular dependencies. The example
class Constants { public const int A = 1; public const int B = A + 1; } shows a class named Constants that has two public constants



What is the method of class?
A method is a member that implements a computation or action that can be performed by an object or class. Methods have a (possibly empty) list of formal parameters, a return value (or void), and are either static or non- static. Static methods are accessed through the class. Non-static methods, which are also called instance methods, are accessed through instances of the class.
Methods can be overloaded, which means that multiple methods may have the same name so long as they have unique signatures. The signature of a method consists of the name of the method and the number, modifiers, and types of its formal parameters. The signature of a method does not include the return type.
What is the property of class?
A property is a member that provides access to an attribute of an object or a class. Examples of properties include the length of a string, the size of a font, the caption of a window, the name of a customer, and so on. Properties are a natural extension of fields. Both are named members with associated types, and the syntax for accessing fields and properties is the same. However, unlike fields, properties do not denote storage locations. Instead, properties have accessors that specify the statements to be executed when their values are read or written.
Properties are defined with property declarations. The first part of a property declaration looks quite similar to a field declaration. The second part includes a get accessor and/or a set accessor. Properties that can be both read and written, include both get and set accessors. The get accessor is called when the property's value is read; the set accessor is called when the property's value is written. In a set accessor, the new value for the property is made available via an implicit parameter named value.

What is the difference between struct and class in C#?
Structs vs classes in C# Structs may seem similar to classes, but there are important differences that you should be aware of. First of all, classes are reference types and structs are value types. By using structs, you can create objects that behave like the built-in types and enjoy their benefits as well.
When you call the New operator on a class, it will be allocated on the heap. However, when you instantiate a struct, it gets created on the stack. This will yield performance gains. Also, you will not be dealing with references to an instance of a struct as you would with classes. You will be working directly with the struct instance. Because of this, when passing a struct to a method, it's passed by value instead of as a reference.
Structs can declare constructors, but they must take parameters. It is an error to declare a default (parameterless) constructor for a struct. Struct members cannot have initializers. A default constructor is always provided to initialize the struct members to their default values.
When you create a struct object using the New operator, it gets created and the appropriate constructor is called. Unlike classes, structs can be instantiated without using the New operator. If you do not use New, the fields will remain unassigned and the object cannot be used until all the fields are initialized.
There is no inheritance for structs as there is for classes. A struct cannot inherit from another struct or class, and it cannot be the base of a class. Structs, however, inherit from the base class object. A struct can implement interfaces, and it does that exactly as classes do,
Structs are simple to use and can prove to be useful at times. Just keep in mind that they're created on the stack and that you're not dealing with references to them but dealing directly with them. Whenever you have a need for a type that will be used often and is mostly just a piece of data, structs might be a good option.
How do I call one constructor from another in C#?
You use : base (parameters) or : this (parameters) just before the actual code for the constructor, depending on whether you want to call a constructor in the base class or in this class.





What is the difference between indexers and properties in C#?
Comparison Between Properties and IndexersIndexers are similar to properties. Except for the differences shown in the following , all of the rules defined for property accessors apply to indexer accessors as well.
Properties
Indexers
Identified by its name.
Identified by its signature.
Accessed through a simple name or a member access.
Accessed through an element access.
Can be a static or an instance member.
Must be an instance member.
A get accessor of a property has no parameters.
A get accessor of an indexer has the same formal parameter list as the indexer.
A set accessor of a property contains the implicit value parameter.
A set accessor of an indexer has the same formal parameter list as the indexer, in addition to the value parameter.
Which interface(s) must a class implement in order to support the foreach statement?
Required interface for foreach statement: A class must implement the IEnumerable and IEnumerator interfaces to support the foreach statement.
Explain Abstract, Sealed, and Static Modifiers in C#.
C# provides many modifiers for use with types and type members. Of these, three can be used with classes: abstract, sealed and static. abstractIndicates that a class is to be used only as a base class for other classes. This means that you cannot create an instance of the class directly. Any class derived from it must implement all of its abstract methods and accessors. Despite its name, an abstract class can possess non-abstract methods and properties. sealedSpecifies that a class cannot be inherited (used as a base class). Note that .NET does not permit a class to be both abstract and sealed. staticSpecifies that a class contains only static members (.NET 2.0).
What's the difference between override and new in C#?
This is all to do with polymorphism. When a virtual method is called on a reference, the actual type of the object that the reference refers to is used to decide which method implementation to use. When a method of a base class is overridden in a derived class, the version in the derived class is used, even if the calling code didn't "know" that the object was an instance of the derived class. For instance: public class Base{ public virtual void SomeMethod() { }} public class Derived : Base{ public override void SomeMethod() { }} ... Base b = new Derived();b.SomeMethod();
will end up calling Derived.SomeMethod if that overrides Base.SomeMethod.
Now, if you use the new keyword instead of override, the method in the derived class doesn't override the method in the base class, it merely hides it. In that case, code like this: public class Base{ public virtual void SomeOtherMethod() { }} public class Derived : Base{ public new void SomeOtherMethod() { }} ... Base b = new Derived();Derived d = new Derived();b.SomeOtherMethod();d.SomeOtherMethod();
Will first call Base.SomeOtherMethod , then Derived.SomeOtherMethod . They're effectively two entirely separate methods which happen to have the same name, rather than the derived method overriding the base method. If you don't specify either new or overrides, the resulting output is the same as if you specified new, but you'll also get a compiler warning (as you may not be aware that you're hiding a method in the base class method, or indeed you may have wanted to override it, and merely forgot to include the keyword).
Name two ways that you can prevent a class from being instantiated.
Ways to prevent a class from instantiated: A class cannot be instantiated if it is abstract or if it has a private constructor.
Explain some features of interface in C#.
Comparison of interface with class (interface vs class):
An interface cannot inherit from a class.
An interface can inherit from multiple interfaces.
A class can inherit from multiple interfaces, but only one class.
Interface members must be methods, properties, events, or indexers.
All interface members must have public access (the default).
By convention, an interface name should begin with an uppercase I.
Can an abstract class have non-abstract methods?
An abstract class may contain both abstract and non-abstract methods. But an interface can contain only abstract methods.
How do I use an alias for a namespace or class in C#?
Use the using directive to create an alias for a long namespace or class. You can then use it anywhere you normally would have used that class or namespace. The using alias has a scope within the namespace you declare it in. Sample code: // Namespace:using act = System.Runtime.Remoting.Activation; // Class:using list = System.Collections.ArrayList;...list l = new list(); // Creates an ArrayListact.UrlAttribute obj; // Equivalent to System.Runtime.Remoting.Activation.UrlAttribute obj
What type of class cannot be inherited?
A sealed class cannot be inherited. A sealed class is used primarily when the class contains static members. Note that a struct is implicitly sealed; so they cannot be inherited.
What keyword must a derived class use to replace a non-virtual inherited method?
new keyword is used to replace (not override) an inherited method with one of the same name.
To know the difference between new and override read:

What's the difference between override and new in C#?
This is all to do with polymorphism. When a virtual method is called on a reference, the actual type of the object that the reference refers to is used to decide which method implementation to use. When a method of a base class is overridden in a derived class, the version in the derived class is used, even if the calling code didn't "know" that the object was an instance of the derived class. For instance: public class Base{ public virtual void SomeMethod() { }} public class Derived : Base{ public override void SomeMethod() { }}...Base b = new Derived();b.SomeMethod();
will end up calling Derived.SomeMethod if that overrides Base.SomeMethod.
Now, if you use the new keyword instead of override, the method in the derived class doesn't override the method in the base class, it merely hides it. In that case, code like this: public class Base{ public virtual void SomeOtherMethod() { }}public class Derived : Base{ public new void SomeOtherMethod() { }}...Base b = new Derived();Derived d = new Derived();b.SomeOtherMethod();d.SomeOtherMethod(); Will first call Base.SomeOtherMethod , then Derived.SomeOtherMethod . They're effectively two entirely separate methods which happen to have the same name, rather than the derived method overriding the base method.
If you don't specify either new or overrides, the resulting output is the same as if you specified new, but you'll also get a compiler warning (as you may not be aware that you're hiding a method in the base class method, or indeed you may have wanted to override it, and merely forgot to include the keyword).

Sunday, June 1, 2008

Sai Baba of Shirdi










SaiBaba of Shirdi
Sai Baba of Shirdi (d. October 15, 1918), also known as Shirdi Sai Baba, was an Indian guru, yogi and fakir who is regarded by his Hindu and Muslim followers as a saint. Some of his Hindu devotees believe that he was an incarnation of Shiva or Dattatreya, and he was regarded as a satguru and an incarnation of Kabir.The name 'Sai Baba' is a combination of Persian and Indian origin; Sāī (Sa'ih) is the Persian term for "holy one" or "saint", usually attributed to Islamic ascetics, whereas Bābā is a word meaning "father" used in Indian languages. The appellative thus refers to Sai Baba as being a "holy father" or "saintly father". His parentage, birth details, and life before the age of sixteen are obscure, which has led to a variety of speculations and theories attempting to explain Sai Baba's origins. In his life and teachings he tried to reconcile Hinduism and Islam: Sai Baba lived in a mosque, was buried in a Hindu temple, practised Hindu and Muslim rituals, and taught using words and figures that drew from both traditions. One of his well known epigrams says of God: "Allah Malik" ("God is Master").Sai Baba taught a moral code of love, forgiveness, helping others, charity, contentment, inner peace, devotion to God and guru. His philosophy was Advaita Vedanta and his teachings consisted of elements both of this school as well as of bhakti and Islam.Sai Baba remains a popular saint and is worshipped mainly in Maharashtra, southern Gujarat, Andhra Pradesh and Karnataka. Debate on his Hindu or Muslim origins continues to take place. He is also revered by several notable Hindu and Sufi religious leaders. Some of his disciples received fame as spiritual figures and saints.