gpt4 book ai didi

c# - 接口(interface)中的枚举 stub ?

转载 作者:太空宇宙 更新时间:2023-11-03 19:33:38 25 4
gpt4 key购买 nike

我在这些接口(interface)所在的项目中的一个 Enum.cs 类中定义了一个枚举。

我有一个名为 IPhoto 的接口(interface),我需要在其中放置一个名为 FileType 的属性,因为该服务中的其他方法需要它,所以我希望任何实现 IPhoto 的类都定义它,以便它们知道它。

这是否看起来不合时宜,或者您只是不会做这样的事情?那我该如何定义呢?

我的意思是我不能只这样做:

MyEnum FileType;

问题是所有文件都有一个类型。在我的具体类(class)中,我表示使用枚举(例如 jpeg 等)。因此,任何实现此功能的类都必须以某种方式明确具有 FileType 属性。

最佳答案

您可以向界面添加属性。查看docs .

public interface ISampleInterface 
{
MyEnum FileType
{
get;
}
}

现在接口(interface)的所有实现都必须为该属性定义一个 getter。

关于c# - 接口(interface)中的枚举 stub ?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3425349/

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