为什么这个实现方法看不到它的兄弟?

编程入门 行业动态 更新时间:2024-10-25 02:29:26
本文介绍了为什么这个实现方法看不到它的兄弟?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我有一个实现接口的类:

I've got a class that implements an interface:

public class SQLiteHHSDBUtils : IHHSDBUtils { void IHHSDBUtils.SetupDB() { . . . if (!TableExists("AppSettings")) . . . bool IHHSDBUtils.TableExists(string tableName) { . . .

它找不到自己的兄弟坐在它下面(如果(!TableExists()):

It can't find its own brother sitting right below it (the if (!TableExists()):

当前上下文中不存在名称TableExists

The name 'TableExists' does not exist in the current context

它怎么能/为什么看不到它?

How can it / why does it not see it?

推荐答案

你有一个显式的接口实现。你不能直接访问你的接口方法,除非你把当前实例转换为接口类型:

You have an explicit interface implementation. You can't access your interface methods directly unless you cast current instance to interface type:

if (!((IHHSDBUtils)this).TableExists("AppSettings"))

来自 13.4.1明确的界面成员实施

在方法调用,属性访问或索引器访问中,无法通过其完全限定名访问显式接口成员实现。成员实施只能通过接口实例访问,并且在这种情况下只能通过其成员名称引用。

It is not possible to access an explicit interface member implementation through its fully qualified name in a method invocation, property access, or indexer access. An explicit interface member implementation can only be accessed through an interface instance, and is in that case referenced simply by its member name.

更多推荐

为什么这个实现方法看不到它的兄弟?

本文发布于:2023-10-16 05:24:48,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1496631.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:兄弟   方法

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!