run time and compile time polymorphism.
Polymorphism is defined as one interface to control access to a general class of actions. 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.
Polymorphism means that functions assume different forms at different times. In case of compile time it is called function overloading. For example, a program can consist of two functions where one can perform integer addition and other can perform addition of floating point numbers but the name of the functions can be same such as add. The function add() is said to be overloaded. 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. In cases of classes constructors could be overloaded as there can be both initialized and uninitialized objects. Here is a program which illustrates the working of compile time function overloading and constructor overloading.
difference between data abstraction and data encapsulation
Data Encapsulation : It is a process of bundling the data, and the functions that use them, as a single unit( at least in C++) . In C++ the data type "class" is used to achieve this.
Data Abstraction : It is a process of exposing only the interfaces and hiding the implementation details from the user. The interface exposed will remain the same: even if the internal implementation changes. This helps the user to use the new functionality without rewriting the client that was designed for previous implementation (strictly speaking ... previous interface).
asp.net page life cycle
Silverlight class hierarchy .
multiple binding in silverlight.
public class TitleConverter : IMultiValueConverter
{
public object Convert(object[] values, Type targetType,
object parameter, System.Globalization.CultureInfo culture)
{
string forename = values[0] as string;
string surname = values[1] as string;
return string.Format("{0}, {1}", surname, forename);
}
}
The IMultiValueConverter interface is much the same as the IValueConverter, except in this case an array of objects are passed to the converter, with each object containing the current bound value for each of our bindings in order.
how to pass values from silverlight to java script or vice verse.
In javascript
var obj = document.getElementById("silverlightControl");
if (obj != null)
obj.Content.MainPage.UpdateText(para);
in .xaml.cs page
class MainPage
{
[ScriptableMember]
public void UpdateText(string result)
{
MessageBox.Show(result);
}
}
class java script method and html control from code behind
HtmlDocument doc = HtmlPage.Document;
// Hook up the simple JavaScript method HTML button.
doc.GetElementById("btnCallJSMethod").AttachEvent("click",
new EventHandler(this.CallGlobalJSMethod));
//call javascript
HtmlPage.Window.Invoke("globalJSMethod", para);
why we use Abstract class.
We use Abstract class and interface to enforce some rules to the classes which extends/implements. For example we can define a class say "Bird" and we can declare methods say "Fly()", "Walk()". This means whatever the class that is derived from Bird has to override or give definition for Fly() and Walk() and therefore we are making sure that all the derived classes follows or has the common functionalities. In other way the classes derived from superclass should have common properties. In addition to this the derive class can have its own methods like "Swim()"...
In case of Abstract class we can define COMMON functionalities in super class and those can be used in the derived class where as in Interface we cant do that. ( this i would say as advantage of abstract class)
In case of Interface the derived class can implement any number of interface but restricted to extend only one abstract class (this i would say as advantage of Interface)
array list and list
public class ItemComparer:IComparer<Item>
{
#region IComparer<Item> Members
public int Compare(Item x, Item y)
{
return y.Freq - x.Freq; //descending sort
//return x.Freq - y.Freq; //ascending sort
}
#endregion
}
static void Main()
{
List<Item> items = new List<Item>();
....
items.Sort(new ItemComparer());
get current url in silverlight apps
HtmlPage.Document.DocumentUri.ToString();
//Application.Current.Host.Source.AbsoluteUri;
manage resource and unmanage resources
Managed resources basically means "managed memory" that is managed by the garbage collector. When you no longer have any references to a managed object (which uses managed memory), the garbage collector will (eventually) release that memory for you.
Unmanaged resources are then everything that the garbage collector does not know about. For example:
Normally you want to release those unmanaged resources before you lose all the references you have to the object managing them. You do this by calling Dispose on that object, or (in C#) using the using statement which will handle calling Dispose for you.
If you neglect to Dispose of your unmanaged resources correctly, the garbage collector will eventually handle it for you when the object containing that resource is garbage collected (this is "finalization"). But because the garbage collector doesn't know about the unmanaged resources, it can't tell how badly it needs to release them - so it's possible for your program to perform poorly or run out of resources entirely.
If you implement a class yourself that handles unmanaged resources, it is up to you to implement Dispose and Finalize correctly.
Whats the difference between Structure, Class and Enumeration
Structures and Enumerations are Value-Types. This means, the data that they contain is stored as a stack on the memory. Classes are Reference-Types, means they are stored as a heap on the memory.
Structures are implicitly derived from a class called System.ValueType. The purpose of System.ValueType is to override the virtual methods defined by System.Object. So when the runtime encounters a type derived from System.ValueType, then stack allocation is achieved. When we allocate a structure type, we may also use the new keyword. We may even make a constructor of a structure, but, remember, A No-argument constructor for a structure is not possible. The structure's constructor should always have a parameter.
So if we define the following structure
struct MyStruct
{
public int y,z;
}
and we create a structure type
MyStruct st = new MyStruct();
In case of a class, no-argument constructors are possible. Class is defined using the class keyword.
A struct cannot have an instance field, whereas a class can.
class A
{
int x = 5; //No error
...
}
struct
{
int x = 5; //Syntax Error
}
A class can inherit from one class (Multiple inheritance not possible). A Structure cannot inherit from a structure.
Enum is the keyword used to define an enumeration. An enumeration is a distinct type consisting of a set of named constants called the enumerator list. Every enumeration has an underlying type. The default type is "int". Note: char cant be the underlying data type for enum. First value in enum has value 0, each consequent item is increased by 1.
enum colors {red, green, blue, yellow};
Here, red is 0, green is 1, blue is 2 and so on.
An explicit casting is required to convert an enum value to its underlying type
int x = (int)colors.yellow;