SoFunction
Updated on 2025-03-07

C# command mode usage example

This article describes the C# command mode. Share it for your reference. The specific implementation method is as follows:

using System;
using ;
using ;
using ;
namespace Command Mode
{
  class Program
  {
    static void Main(string[] args)
    {
      Receiver r = new Receiver();
      Command c = new ConcreteCommand(r);
      Invoker i = new Invoker();
      (c);
      ();
    }
    public abstract class Command
    {
      private Receiver receiver;
      internal Receiver Receiver
      {
        get { return receiver; }
        set { receiver = value; }
      }
      public Command(Receiver receiver)
      {
         = receiver;
      }
      public abstract void Execute();
    }
    public class Receiver
    {
      public void Action()
      {
        ("Get the receiver's action method!");
      }
    }
    public class ConcreteCommand : Command
    {
      public ConcreteCommand(Receiver receiver) : base(receiver) { }
      public override void Execute()
      {
        ();
      }
    }
    public class Invoker
    {
      private Command command;
 
      internal Command Command
      {
        get { return command; }
        set { command = value; }
      }
      public void SetCommand(Command command)
      {
         = command;
      }
      public void ExectueCommand()
      {
        ();
      }
    }
  }
}

I hope this article will be helpful to everyone's C# programming.