C# 如何解决这个代码复用问题?
来源:
编辑:
时间:2025-06-28 08:45:15

很可惜,你离最终答案就差最后一步了。
在 C# 中静态成员可以是抽象或者虚拟的,因此你只需要把你的 Creature 类型换成接口类型,然后把 LegNum 这个静态属性定义在接口中,并设置为抽象成员即可。
首先创建一个 ICreature 接口类型:interface ICreature { abstract static int LegNum { get; set; } } 然后在你的 Ant、Octopus、Centipede 类型中实现这个接口: class Ant : ICreature { public static int LegNum { get; set;…。
-
{dede:pagebreak/}


网友评论:
{dede:include file='ajaxfeedback.htm' /}
栏目分类

最新文章

热门文章
