c# - 方法无法显式调用运算符或访问器

标签 c#

我添加了.dll:AxWMPLib并使用了get_Ctlcontrols()方法,但显示如下错误:

AxWMPLib.AxWindowsMediaPlayer.Ctlcontrols.get': cannot explicitly call operator or accessor



这是我使用get_Ctlcontrols()方法的代码:
this.Media.get_Ctlcontrols().stop();

我不知道为什么会出现此错误。谁能解释我以及如何解决这个问题?

最佳答案

看起来您正在尝试通过显式调用其get方法来访问属性。

尝试以下操作(注意,缺少get_()):

this.Media.Ctlcontrols.stop();

这是一个关于属性如何在C#中工作的小例子-只是为了使您理解,这并不假装是准确的,因此请阅读比这更严重的内容:)
using System;

class Example {

    int somePropertyValue;

    // this is a property: these are actually two methods, but from your 
    // code you must access this like it was a variable
    public int SomeProperty {
        get { return somePropertyValue; }
        set { somePropertyValue = value; }
    }
}

class Program {

    static void Main(string[] args) {
        Example e = new Example();

        // you access properties like this:
        e.SomeProperty = 3; // this calls the set method
        Console.WriteLine(e.SomeProperty); // this calls the get method

        // you cannot access properties by calling directly the 
        // generated get_ and set_ methods like you were doing:
        e.set_SomeProperty(3);
        Console.WriteLine(e.get_SomeProperty());

    }

}

关于c# - 方法无法显式调用运算符或访问器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/65468460/

相关文章:

c# - 在 C# 中优化多个调度通知算法?

c# - 针对 ADFS 的身份验证、针对 sql server 的授权

c# - 将二维整数作为只读/常量存储在单独的类中,同时保持不公开

c# - 在没有存储过程的情况下从 C# 将二进制数据插入 SQL

C# DataRow 所有项目数组到单个字符串,追加 |到每个阵列

c# - 映射到嵌套类

c# - 我需要指导来构建我的第一个 C# 项目

c# - 从哪里获得适用于 Windows 的更新 MemCached?

c# - SPItemEventReceiver 类中的确认框

针对字符串的 c# 单元测试日期时间