Partial class was a new feature that has been added in c# 2.0. which allows you to define a class on more than one file. If we want to define a class in multiple files, the name of the class in all files should be same.
The Advantages in this approach will be like
namespace oopsproject
{
partial class parts
{
public void method1()
{
console.writeLine("method one");
}
public void method2()
{
console.writeLine("method two");
}
}
2. Add a code file part2.cs and write the follows?
using system;
namespace oopsproject
{
partial class parts
{
public void method3()
{
console.writeLine("method three");
}
public void method4()
{
console.writeLine("method four");
}
}
3. Add a class testparts.cs and write code?
using system;
namespace oopsproject
{
class Testparts
{
Static Void Main(String[]args)
{
parts p= new parts();
p.method1();
p.method2();
p.method3();
p.method4();
Console.ReadLine();
}
}
}
OUTPUT :
The Advantages in this approach will be like
- Splitting of huge volumes of code or splitting of related code makes it easier to manage.
- Gives a flexibility for multiple programmers to work on the same class.
- Add a code file part1.cs and write the following?
namespace oopsproject
{
partial class parts
{
public void method1()
{
console.writeLine("method one");
}
public void method2()
{
console.writeLine("method two");
}
}
2. Add a code file part2.cs and write the follows?
using system;
namespace oopsproject
{
partial class parts
{
public void method3()
{
console.writeLine("method three");
}
public void method4()
{
console.writeLine("method four");
}
}
3. Add a class testparts.cs and write code?
using system;
namespace oopsproject
{
class Testparts
{
Static Void Main(String[]args)
{
parts p= new parts();
p.method1();
p.method2();
p.method3();
p.method4();
Console.ReadLine();
}
}
}
OUTPUT :
No comments:
Post a Comment