articles

home / developersection / articles / partial class

Partial Class

Anonymous User 6477 15-Jul-2010

When we want to split class we use partial keyword. The main advantage of partial

class is that more than one programmer can work on same class at a time i.e. they

can implement same class.

Example

 Partial Class

 

private void btnAdd_Click(object sender, EventArgs e)
        {
//creating instance of class
            c c1 = new c();
//calling add() method of class
            MessageBox.Show(c1.add(2,4).ToString());
        }
 
        private void btnSub_Click(object sender, EventArgs e)
        {
            c c1 = new c();
//calling sub() method of class
            MessageBox.Show(c1.sub(4,3).ToString());
        }
   
//half of the class is defined here
    public partial class c
    {
        public int add(int a, int b)
        {
            return a+b;
        }
    }       
 //another half of class c
public int sub(int a, int b)
        {
            return a - b;
        } 

Screen shots

Partial ClassPartial Class

 

 


Updated 07-Sep-2019

I am a content writter !


Message

Leave Comment

1 Comments

Comments

Liked By