s

C# partial class edit button Edit

author
Rakesh Kumar Sutar | calendar 20 January 2021 | 2188

Introduction

C# provides a special ability to implement the functionality of a single class into multiple files and all these files are combined into a single class file when the application is compiled. A partial class is created by using a partial keyword. This keyword is also useful to split the functionality of methods, interfaces, or structure into multiple files.

Example

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

namespace Hello_World
{

    public partial class Coordinates
    {
        private int x;
        private int y;

        public Coordinates(int x, int y)
        {
            this.x = x;
            this.y = y;
        }
    }

    public partial class Coordinates
    {
        public void PrintCoordinates()
        {
            Console.WriteLine();
            Console.WriteLine("\tCoordinates: {0},{1}", x, y);
        }
    }

    class Programs
    {
        static void Main(String[] args)
        {
            Coordinates myCoords = new Coordinates(10, 15);
            myCoords.PrintCoordinates();

           
            Console.WriteLine("\tPress any key to exit.");
            Console.ReadKey();
        }
    }
    
}

Output