Thursday, July 1, 2010

IMPLEMENTING ICOMPARABLE INTERFACE

Array of types that support IComparer, you can sort that array without providing any explicit reference to IComparer. In that case, the elements of the array are cast to the default implementation of IComparer . However, For sorting or comparison capability for custom objects It can be used.

Its works under System.Collections Namespace

IComparable
The role of IComparable is to provide a method of comparing two objects of a particular type.

Example Programe

using System;
class combo:IComparable
{
public int id;
public string name;
public combo(string name1,int x)
{
name=name1;
id=x;
}
public int CompareTo(object o)
{
combo temp=(combo) o;
if(this.id>temp.id)
return (1);
if(this.idreturn (-1);
else
return (0);
}
}
class icomparable
{
public static void Main(string[] args)
{
combo[] c=new combo[3];
c[0]=new combo("aaa",123);
c[1]=new combo("bbb",12);
c[2]=new combo("ccc",1);
Array.Sort(c);
foreach(combo m in c)
Console.WriteLine(m.name+"\t"+m.id);
}
}

IMPLEMENTING IENUMERABLE INTERFACE

IMPLEMENTING IENUMERABLE INTERFACE
Exposes the enumerator, which supports a simple iteration over a non-generic collection
Its works under System.Collections Namespace

IEnumerable, IEnumerator interfaces, which facilitates the iterative access in a custom collection
Implementation default method GetEnumerator of IEnumerable interface

Example Programe

using System;
using System.Collections;
class car:IEnumerable
{
private car[] carr;
public string name;
public car(string s)
{name=s;}
public car()
{
carr=new car[3];
carr[0]=new car("san");
carr[1]=new car("man");
carr[2]=new car("van");
}
public IEnumerator GetEnumerator()
{return carr.GetEnumerator();}
}
class enumInterface
{
public static void Main(string[] args)
{
car o=new car();
foreach(car c in o)
{
Console.WriteLine(c.name);
}
}
}

Binary operators overloading

Binary operators overloading there are two arguments
the general form of operator function for binary operators is as follows.
One of the parameters has to be of a type in which the operator is declared. They include +, -, *, /, %, &, |, ^, <<, >>, ==, !=, >, <, >=, and <=.
public static return_type operator op (Type1 t1, Type2 t2)
{
//Statements
}

Example

public static biop operator +(biop ob1,biop ob2)
{
biop b=new biop();
b.real=ob1.real+ob2.real;
b.im=ob1.im+ob2.im;
return b;
}


Example program in C# Console application

using System;
class biop
{
public int real,im;
public biop(){}
public biop(int r,int i)
{
real=r;
im=i;
}
public void disp(){Console.WriteLine(real+"+i"+im);}
public static biop operator +(biop ob1,biop ob2)
{
biop b=new biop();
b.real=ob1.real+ob2.real;
b.im=ob1.im+ob2.im;
return b;
}
}
class binaryoperator
{
public static void Main(string[] args)
{
biop b1=new biop(5,5);
b1.disp();
biop b2=new biop(2,2);
b2.disp();
biop b3=b1+b2;
b3.disp();
}
}

unary operators overloading

unary operators overloading there is only one argument
the general form of operator function for unary operators is as follows.

public static return_type operator op (Type t)
{}

Example

public static uop operator -(uop ob)
{
ob.a=-ob.a;
ob.b=-ob.b;
return ob;
}


Example Program

using System;
class uop
{
public int a,b;
public uop(int a1,int b1)
{
a=a1;
b=b1;
}
public void disp(){Console.WriteLine(a);Console.WriteLine(b);}

public static uop operator -(uop ob)
{
ob.a=-ob.a;
ob.b=-ob.b;
return ob;
}
}
class unaryoperator
{
public static void Main(string[] args)
{
uop u=new uop(-10,-10);
u.disp();
uop u1=-u;
u1.disp();
}
}

Thursday, June 24, 2010

Diffetence web versions

Difference web versions

Web 1.0
This is mostly ready only purpose, For example HTML and portals web forms.

Web 2.0

This is wildly read- write web purpose. For example blogs, sharing content, Wikipedia,XML and RSS in the web.

Web 3.0

This is describes the portable personal web, For example web widgets and drag & drop (iGoogle)