Does C# (.NET) support partial implementation?

Thursday, June 25, 2009

Does C# (.NET) support partial implementation?
No.

the following program will throw an error.

using System;
using System.Collections.Generic;
using System.Text;

namespace OPPTest3
{
interface IA
{
void x();
void y();
}

class IAClass : IA
{
public void x()
{
Console.Out.Write("test x");
}

}
class Program
{
static void Main(string[] args)
{
IAClass m = new IAClass();
m.x();
m.y();
}
}
}

Can we leave a virtual function in an abstract class without implementing in the derived class

Does c# support pure virtual function?
No.
Instead you can use abstract function which is also called as a pure virtual function.
abstract class abTest
{
public abstract void a();

}

Can we leave a virtual function in an abstract class without implementing in the derived class ?
No. It will throw an error.

using System;
using System.Collections.Generic;
using System.Text;

namespace OppTest4
{
abstract class abTest
{
public abstract void a();

}

class UsesabTest : abTest
{
//public override void a()
//{
// Console.Out.Write("a");
//}

public void x()
{
Console.Out.Write("x");
}
}

class Program
{
static void Main(string[] args)
{
}
}
}

Can a base class contain its derived class?

Can a base class contain its derived class?
Yes. But the reverse is not possible.

using System;
using System.Collections.Generic;
using System.Text;

namespace OppsTest
{
class A
{
int i = 1;

public A()
{
}

public void testa()
{
Console.Out.Write(i);
}
}

class B : A
{
int j = 3;
public B()
{
}

public void testb()
{
Console.Out.Write(j);
}

}




class Program
{
static void Main(string[] args)
{
A a = new B();
a.testa();
Console.In.Read();
}
}
}

Class implementing Interface

using System;
using System.Collections.Generic;
using System.Text;

namespace OppTest2
{
interface IA
{
void x();
void y();
}

class IAClass : IA
{
public void x()
{
Console.Out.Write("test x");
}
public void y()
{
Console.Out.Write("test y");
}
}
class Program
{
static void Main(string[] args)
{
IAClass m = new IAClass();
m.x();
m.y();
}
}
}

how to implement a pure virtual function in c#?

how to implement a pure virtual function in c#?

using System;
using System.Collections.Generic;
using System.Text;

namespace OppTest4
{
abstract class abTest
{
public abstract void a();

}

class UsesabTest : abTest
{
public override void a()
{
Console.Out.Write("a");
}

public void x()
{
Console.Out.Write("x");
}
}

class Program
{
static void Main(string[] args)
{
UsesabTest mn = new UsesabTest();
mn.a();
}
}
}

LinkWithin

Blog Widget by LinkWithin

Recommended Books