program.cs

来自「这是asp.net^和Visual C++Sharp编写的串并口通讯的书籍 源代」· CS 代码 · 共 61 行

CS
61
字号
using System;
using System.Collections.Generic;
using System.Text;
using System.Collections;

namespace _1
{
    abstract class ColorRGBPrototype
    {
        public abstract ColorRGBPrototype Clone();
    }
    class ColorRGB : ColorRGBPrototype
    {
        private int red, green, blue;
        public ColorRGB(int red, int green, int blue)
        {
            this.red = red;
            this.green = green;
            this.blue = blue;
        }
        public override ColorRGBPrototype Clone()
        {
            return (ColorRGBPrototype)this.MemberwiseClone();
        }

        public void Display()
        {
            Console.WriteLine("颜色值: {0},{1},{2}",
              red, green, blue);
        }
    }
    class ColorRGBManager
    {
        Hashtable colors = new Hashtable();
        public ColorRGBPrototype this[string name]
        {
            get { return (ColorRGBPrototype)colors[name]; }
            set { colors.Add(name, value); }
        }
    }
    class PrototypeApp
    {
        public static void Main(string[] args)
        {
            ColorRGBManager colormanager = new ColorRGBManager();
            colormanager["red"] = new ColorRGB(255, 0, 0);
            colormanager["green"] = new ColorRGB(0, 255, 0);
            colormanager["blue"] = new ColorRGB(0, 0, 255);
            string colorName = "red";   //开始克隆
            ColorRGB red = (ColorRGB)colormanager[colorName].Clone();
            red.Display();
            colorName = "green";
            ColorRGB green = (ColorRGB)colormanager[colorName].Clone();
            green.Display();
            colorName = "blue";
            ColorRGB blue = (ColorRGB)colormanager[colorName].Clone();
            blue.Display();
        }
    }
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?