Saturday, October 20, 2012

Difference between Sealed and Partial class in C#.Net

Sealed Class:
1.Sealed is a keyword
2.Sealed class are not inheritable
3.When ever a class is providing full functionality as per the requirements,then that class need to be declared as sealed

Partial class:
1.Partial keyword can be used with classes and interfaces
2.When a class or interface need be written in multiple locations with same name then those class or interfaces need to be partial

Here i will given an example on Partial class
//Open windows form project.Then place a button
//Code in General declaration
Interface test
{
void read();
void print();
}
Partial class testchild:Test
{
public void read()
{
Message.Show("Read");
}
}//testchild
Partial class testchild
{
public void print()
{
Message.Show("print");
}

//Code for button click
{
testchild tc=new testchild();
tc.read();
tc.print();
test t=new test();
t.read();
t.print();
}

No comments:

Bel