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

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

本文介绍了方法无法显式调用运算符或访问器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I added .dll: AxWMPLib and using method get_Ctlcontrols() but it show error like:

这是我的代码,使用 get_Ctlcontrols()方法:

This is my code using get_Ctlcontrols() method:

this.Media.get_Ctlcontrols().stop();

我不知道为什么会出现此错误。有人可以向我解释以及如何解决此问题吗?

I don't know why this error appears. Can anyone explain me and how to resolve this problem?

推荐答案

您似乎正在尝试通过显式调用属性来访问属性

It looks like you are trying to access a property by calling explicitly its get method.

尝试一下(注意 get _ ()丢失):

Try this (notice that get_ and () are missing):

this.Media.Ctlcontrols.stop();

以下是有关属性在C#中如何工作的一个小示例-只是为了让您理解,这不是假装是准确的,所以请阅读比这更严重的文章:)

Here is a small example about how properties work in C# - just to make you understand, this does not pretend to be accurate, so please read something more serious than this :)

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());

    }

}

这篇关于方法无法显式调用运算符或访问器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-10 23:29