Using partial keyword in C# Language

Introduction

You can split a class up into different files with using partial keyword. Partial keyword is used when we want to make the Class definition into different file within same namespace. Science two same name class create  in a  namespace. A class can span multiple files too, but need to use the partial keyword when you declare it.

Program

using System;

using System.Collections.Generic;

using System.Linq;

 

namespace twosameclass

{

    partial class Program     // class name program

    {

        public void function1()

        {

            Console.WriteLine("Function1 of partial Class");

 

 

        }

    }

    partial class Program    //class name program are both same

    {

        public void function2()

        {

            Console.WriteLine("Function2 of Partial Class");

        }

 

        static void Main()

        {

            Program obj = new Program();

            obj.function1();

            obj.function2();

 

        }

    }

}


Output


partial.jpg


Ebook Download
View all
Learn
View all