So what the use of it?
- when the size of the file is getting bigger, it is harder to maintain, so one of the way is to split classes base on its functionality.
- it will allow programmers to add some definition of the class simultaneously
- when working with automatically generated source, code can be added to the class without having to recreate the source file. Visual Studio uses this approach when creating Windows Forms, Web Service wrapper code, and so on. You can create code that uses these classes without having to edit the file created by Visual Studio.
using System;we can break down the code into several files
using System.Collections.Generic;
using System.Text;
public class Company
{
static void Main(string[] args)
{
ITDepartment a = new ITDepartment();
HRDepartment b = new HRDepartment();
Console.ReadLine();
}
private class ITDepartment
{
public ITDepartment()
{
Console.WriteLine(”itdepartment”);
}
}
private class HRDepartment
{
public HRDepartment()
{
Console.WriteLine(”hrdepartment”);
}
}
}
Company.cs
using System;Company.HRDepartment.cs
using System.Collections.Generic;
using System.Text;
public partial class Company
{
static void Main(string[] args)
{
ITDepartment a = new ITDepartment();
HRDepartment b = new HRDepartment();
Console.ReadLine();
}
}
using System;Company.ITDepartment.cs
using System.Collections.Generic;
using System.Text;
public partial class Company
{
private class HRDepartment
{
public HRDepartment()
{
Console.WriteLine("hrdepartment");
}
}
}
using System;Kindly refer to this tutorial for other reference
using System.Collections.Generic;
using System.Text;
public partial class Company
{
private class ITDepartment
{
public ITDepartment()
{
Console.WriteLine("itdepartment");
}
}
}
No comments:
Post a Comment