Tuesday, May 15, 2012

What is a partial class and how to use in c sharp

It was introduced under 2.0 framework which allows you to split a class o n to multiple files
Advantages:
Splitting huge volumes of code into multiple files which makes managing easier.Allows multiple programmers to work on the same class at the same time.grouping related code of a class in separate files
Here i will show how to develop a partial class in csharp.For this add a class to the project naming it as File1.cs and write the following code
partial class parts
{
public void test1()
{
Console.Writeline("method1");
}
public void test2()
{
Console.Writeline("method2");
}
}
add one more class naming it as File2.cs
 partial class parts { public void test3() { Console.Writeline("method3"); } public void test4() { Console.Writeline("method4"); } } Now to test the class add one more class to the project naming it as test parts.cs and write the following class testparts { static void main() { parts p= new parts(); p.test1(); p.test2(); p.test3(); p.test4(); Console.ReadLine();
} }

No comments:

Bel