gpt4 book ai didi

c# - 将接口(interface)实现限制为结构?

转载 作者:行者123 更新时间:2023-11-30 14:07:09 24 4
gpt4 key购买 nike

C# 中的接口(interface)可以继承另一个接口(interface),例如

interface IFoo : IComparable { }

另一方面,以下声明是非法的:

interface IBar : struct { } // Invalid syntax

有没有什么方法可以声明接口(interface),以便将实现类型限制为 struct

最佳答案

Is there any way an interface can be declared so that the implementing type is constrained to be a struct?

不,这目前是不可能的,反之亦然(确保接口(interface)由类实现)。


就文档而言,我能找到的最接近的东西是这个 Interfaces , Interfaces (c#) , Inheritance - Interfaces .我怀疑 MS 官方网站上不会有任何内容,只是因为(在大多数情况下)没有关于不存在的功能的文档(忽略功能请求或进行中的功能),这可以被认为是非-存在的特征。

最近 excerpt我能找到

A class or struct can implement multiple interfaces. ...

关于c# - 将接口(interface)实现限制为结构?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42999660/

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