C# virtual static method

前端 未结 9 1299
盖世英雄少女心
盖世英雄少女心 2020-12-14 01:27

Why is static virtual impossible? Is C# dependent or just don\'t have any sense in the OO world?

I know the concept has already been underlined but I did not find a

9条回答
  •  抹茶落季
    2020-12-14 01:45

    While technically its not possible to define a static virtual method, for all the reasons already pointed out here, you can functionally accomplish what I think your trying using C# extension methods.

    From MSDN:

    Extension methods enable you to "add" methods to existing types without creating a new derived type, recompiling, or otherwise modifying the original type.

    Check out C# Extension Methods (C# Programming Guide) for more details.

提交回复
热议问题