Partial methods and partial class analysis in C

  • 2020-12-09 00:59:34
  • OfStack

This article analyzes the partial methods and partial classes in C#. Share to everybody for everybody reference.

The specific code is as follows:


using System; namespace Partial
{
    class Program
    {
        static void Main(string[] args)
        {
            A a = new A();
        }
    }     partial class A
    {
        public A()
        {
            PrintHello();
            PrintWorld();
            Console.Read();
        }         partial void PrintHello()
        {
            Console.Write("Hello");
        }
    }     partial class A
    {
        // Partial methods must have the following declaration, and the return type can only be void And do not accept Out parameter
        // A partial method can exist only with a declaration and not implement it
        // Unimplemented partial methods are automatically removed by the compiler during code generation without additional overhead
        partial void PrintHello();
        partial void PrintWorld();
    }
}

Hopefully this article has helped you with your C# programming.


Related articles: