Archive for November, 2008

Virtual Override

Monday, November 24th, 2008

Similar to C# code for virtual we provide you Virtual OverRide code

class zzz
{
public static void Main()
{
yyy a = new yyy();xxx b = new xxx();yyy c = new xxx();
a.abc();a.pqr();a.xyz();
b.abc();b.pqr();b.xyz();
c.abc();c.pqr();c.xyz();
}}
class yyy
{
public virtual void abc()
{System.Console.WriteLine(”yyy abc”);}
public virtual void pqr()
{System.Console.WriteLine(”yyy pqr”);}
public virtual void xyz()
{System.Console.WriteLine(”yyy xyz”);}
}
class xxx : yyy
{
public override void abc()
{System.Console.WriteLine(”xxx abc”);}
public new void pqr()
//New means that the function pqr is a new function and it has absolutely nothing to do with the pqr in the base class
{
System.Console.WriteLine(”xxx pqr”);
}
public void xyz()
{
System.Console.WriteLine(”xxx xyz”);
}}

Virtual.cs C# code

Wednesday, November 5th, 2008

Virtual.cs
===

class zzz
{
public static void Main()
{
yyy a = new xxx();
yyy b = new vvv();
xxx c = new vvv();
a.abc();a.pqr();a.xyz();b.abc();b.pqr();b.xyz();c.abc();c.pqr();c.xyz();}}
class yyy
{
public void abc()
{System.Console.WriteLine(”yyy abc”);}
public virtual void pqr()
{System.Console.WriteLine(”yyy pqr”);}
public virtual void xyz()
{System.Console.WriteLine(”yyy xyz”);}
}
class xxx : yyy
{
public virtual void abc()
{System.Console.WriteLine(”xxx abc”);}
public new void pqr()
{System.Console.WriteLine(”xxx pqr”);}
public override void xyz()
{System.Console.WriteLine(”xxx xyz”);}
}
class vvv : xxx
{
public override void abc()
{System.Console.WriteLine(”vvv abc”);}
public void xyz()
{System.Console.WriteLine(”vvv xyz”);}
}

Using.cs
===

using System;
using ashish;
class zzz {
static void Main()
{
yyy.abc();
}
}
namespace ashish
{
class yyy
{
public static void abc()
{
Console.WriteLine(”abc”);
}
}
}
//After the word using you can only write the name of a namespace…