21 Sep 2017

What is partial class with example


Partial class is used to in single namespace. Partial class can't we declare in different namespace. Partial class used to multi pal source file in single namespace ,but it will be compiled only single one classs at run time

Example:-
Suppose that we have a class "Rock_Programmer" The "Rock_Programmer" class divided into source file  Rock_Programmer1"  and "Rock_Programmer2" but the compile 
the source code then create a single class.

Example of Partial class:-

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace What_is_partial_class
{
    partial class Partial1
    {
        public void Rock1()
        {
            Console.WriteLine("Hello Rock Programmer");
        }
    }
    partial class Partial1
    {
        public void Rock2()
        {
            Console.WriteLine("I am Partial Class");
        }
    }
    class Program
    {
        static void Main(string[] args)
        {
            Partial1 obj = new Partial1();
            obj.Rock1();
            obj.Rock2();
            Console.ReadKey();
        }
    }
}

Output is:-


No comments:
Write comments

Contact Form

Name

Email *

Message *

© 2014 Rock Programmer . Designed by Bloggertheme9
Powered by Rock Programmer.