gpt4 book ai didi

c# - 扩展Int以在c#中实现接口(interface)

转载 作者:行者123 更新时间:2023-11-30 19:11:32 25 4
gpt4 key购买 nike

是否可以在 C# 中(我认为不可能)扩展 int 以实现接口(interface)(无需创建包装类)?

我有这样的界面

public interface IActionLoggerObject
{
string GetForLogging();
}

我希望(概念上)能够做到这一点:

public class int:IActionLoggerObject
{
string IActionLoggerObject.GetForLogging() { return "s"; }
}

最佳答案

Is it possible (and i think it is not) to (in c#) extend "int" to implement an interface (without creating a wrapper class)?

没有。您永远无法更改现有类型实现的接口(interface)。

目前尚不清楚您为什么要这样做,但创建包装器类几乎可以肯定是前进的方向。

关于c# - 扩展Int以在c#中实现接口(interface),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11108848/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com