Tuesday 28 October 2014

Partial Classes in C#: Understanding Their Purpose and Implementation

What is a Partial Class.

Partial class is one of the most important thing when we work on larger project we can break the concept of interface,class into one or more thing and use partial keyword with each of this so that many of the person can work on them at same time

"To split the definition of a class or a struct, an interface or a method over two or more source files is known as Partial Class."
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace UsingPartialClass
{
    public partial class book
    {
        public void study()
        {
            Console.WriteLine("Reading..........");
        }
    }

    public partial class book
    {
        public void watch()
        {
            Console.WriteLine("watch movie........");
        }
    } 
}

class Program
    {
        static void Main(string[] args)
        {
            book obj = new book();
            obj.study();
            obj.watch();

            Console.ReadKey();
        }
    }
it is very necessary to use partial keyword with each portion of the partial class 
access specifier is also attach with each part of partial class




we can create partial interface,struct and method.
we can create partial delegate and enumrator.
Different parts of a partial class can inherit from different interfaces.
nested classes can be specified as partial classes even if the containing class is not partial. An example is shown below.

No comments:

Post a Comment

AdSense

The Ultimate Guide to Interceptors: Understanding Their Power and Functionality

  The Ultimate Guide to Interceptors: Understanding Their Power and Functionality An interceptor is a service that can intercept HTTP reques...

Follow