Note: I have moved to wordpress. New URL is "Technology Made Easy"

Wednesday, July 30, 2008

C# : Reference of Abstract class containing derived class instance

You could have seen a object initialization like this


A a = new B();


where B is a derived class of A. But we cannot do the other way around.


B b = new A(); // because A is an abstract class


Take a look into the below example and its output.You can understand how it
works.






using System;
using System.Text;

namespace aruns_code
{
class testAbstract
{
[STAThread]
static void Main(string[] args)
{
der derObj = new der();
derObj.nonAbs();

Console.WriteLine("\n\n");

abs absObj = new der();
absObj.nonAbs();
absObj.absMethod();
}
}

class der : abs
{
public der()
{
Console.Write("initialized der\n");
}

public override void absMethod()
{
Console.Write("inside der\n");
}

public new void nonAbs()
{
Console.Write("inside nonAbs of der\n");
}
}


abstract class abs
{
public abs()
{
Console.Write("initialized abs\n");
}

public abstract void absMethod();

public void nonAbs()
{
Console.Write("inside nonAbs of abs\n");
}
}

}




The following is the output




initialized abs
initialized der
inside nonAbs of der

initialized abs
initialized der
inside nonAbs of abs
inside der

Thursday, November 1, 2007

Introduction to MONO.net

Have you ever thought of installing and running ASP.NET web application on linux?Yes. it is made possible using MONO framework. It is actually an open source implementation of .NET framework. It emulates .NET framework. So you can write your codebehind in C#.net just like you were writing for your usual ASP.NET application and compile it. Now put up a linux box with mono in it. Now you can install and run your ASP.NET application straight from the linux box!! It is really great!!

Wednesday, May 16, 2007

How to remove all options from a list box using javascript?


function clearListBox(listboxID)
{
// returns 1 if all items are sucessfully removed
// otherwise returns zero.
var mylistbox = document.getElementById(listboxID);
if(mylistbox == null)
return 1;
while(mylistbox.length > 0)
{
mylistbox.remove(0);
}
return 1;
}

about me

I am a software engineer from India...
Coding was my hobby...
now, Coding is my profession...

Ratings by outbrain