Partial Classes definition with example in C#.Net

Partial Classes

Partial types feature is one of the important feature in dotnet framework. Using this we can define single class in multiple places or multiple files also. At the time of compilation all these classes are combine and work as a single class.

For delegate and enumeration this partial modifier is not available.

Example

     class Program:derivedClass
    {
        static void Main(string[] args)
        {
            derivedClass objDerived = new derivedClass();
            objDerived.ExamplePartial();
        }
    }


    public partial class PartialClassExample
    {
        public void GetRollNo()
        {
            Console.WriteLine("this is first part of partial class");
        }
    }
    public partial class PartialClassExample
    {
        public void GetStudentName()
        {
            Console.WriteLine("this is second part of partial class");
        }
    }

    public class derivedClass : PartialClassExample
    {
        public void ExamplePartial()
        {
            GetRollNo();
            GetStudentName();
            Console.WriteLine("this is derived class");
            Console.ReadLine();
        }
    }

Share this post :

Post a Comment

Please give your valuable feedback on this post. You can submit any ASP.NET article here. We will post that article in this website by your name.

 
Support : Ranga Rajesh Kumar
Copyright © 2012. ASP.NET Examples - All Rights Reserved
Site Designed by Ranga Rajesh Kumar