方法不能显式调用运算符或访问器
本文关键字:访问 运算符 调用 不能 方法 | 更新日期: 2023-09-27 18:35:24
我添加了.dll:AxWMPLib
并使用方法get_Ctlcontrols()
但它显示错误如下:
AxWMPLib.AxWindowsMediaPlayer.Ctlcontrols.get':不能显式调用运算符或访问器
这是我使用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());
}
}