美文网首页
2020-03-07【c#】interface 2

2020-03-07【c#】interface 2

作者: 持刀的要迟到了 | 来源:发表于2020-03-07 19:06 被阅读0次

今天看了一个写法。
大概是这个意思:

using System;

namespace InterfaceTest
{
    public interface IFuckableItem
    {
        int GetItemType();
        string Fuck();
    }

    public abstract class Item
    {
    }

    public class Stone : Item
    {

    }

    public abstract class Animal : Item, IFuckableItem
    {
        public abstract int GetItemType();
        public abstract string Fuck();
    }

    public abstract class ChongQiWawa : Item, IFuckableItem
    {
        public abstract int GetItemType();
        public abstract string Fuck();
    }

    public abstract class Human : Item, IFuckableItem
    {
        public abstract int GetItemType();
        public abstract string Fuck();
    }

    //------------------------------------------------------------

    public class Sheep : Animal
    {
        public override int GetItemType()
        {
            return 0;
        }

        public override string Fuck()
        {
            return "Mie mie mie";
        }
    }

    public class JishangShengyao3 : ChongQiWawa
    {
        public override int GetItemType()
        {
            return 1;
        }

        public override string Fuck()
        {
            return "------";
        }
    }

    public class Girl : Human
    {
        public override int GetItemType()
        {
            return 2;
        }

        public override string Fuck()
        {
            return "啊,好哥哥,不要啊";
        }
    }



    class Program
    {
        static void Main(string[] args)
        {
            Item[] items = new Item[4]
            {
                new Stone(),
                new Sheep(),
                new JishangShengyao3(),
                new Girl()
            };

            IFuckableItem girlItem;

            for (int i = 0; i < items.Length; ++i)
            {
                //if (items[i] is Girl)
                //{
                //    Console.WriteLine((items[i] as Girl).Fuck());
                //}

                if ((girlItem = items[i] as IFuckableItem) != null && girlItem.GetItemType() == 2)
                {
                    Console.WriteLine(girlItem.Fuck());
                }
            }

            Console.ReadLine();
        }
    }
}

相关文章

  • 2020-03-07【c#】interface 2

    今天看了一个写法。大概是这个意思:

  • c# interface接口

    1 接口就是一种规范 协议 约定好某种规范就可以使用通用的代码 2 定义了一组具有各种功能的方法(只有一种声明,但...

  • C# 接口(interface)

    接口包含类或结构体可以实现的一组相关功能的定义。 实现接口的任何类或结构体都必须实现其所有成员。 接口无法实例化,...

  • C#——关于接口interface

    关键字 interface 接口,很多高级面向对象编程语言都有接口这一个知识点。这里记录一下关于接口的一些东西:接...

  • C#之interface(接口)

    定义: 接口是指定一组函数成员而不实现成员的引用类型,其他类型-类和接口可以实现接口。 接口是一个引用类型,通过接...

  • c# interface 接口 笔记

    文末有“实战代码” 接口表示一种能力A.做这项工作需要一个钳工(木匠/程序员)钳工是一种“能力”,不关心具体是谁B...

  • 2018-12-06

    1、c#注释///****//////2 C#源码的文件格式:.cs3 C#输出Console.writeLine...

  • 2019-01-03第一学期复习

    1、c#注释///****//////2 C#源码的文件格式:.cs3 C#输出Console.writeLine...

  • 2019-01-03 C#总复习

    1、c#注释///****//////2 C#源码的文件格式:.cs3 C#输出Console.writeLine...

  • 知识总结

    1、c#注释///****//////2 C#源码的文件格式:.cs3 C#输出Console.WriteLine...

网友评论

      本文标题:2020-03-07【c#】interface 2

      本文链接:https://www.haomeiwen.com/subject/gflhdhtx.html