我添加了.dll:AxWMPLib和使用方法,get_Ctlcontrols()但它显示如下错误:
AxWMPLib.AxWindowsMediaPlayer.Ctlcontrols.get':无法显式调用运算符或访问器
这是我的代码使用get_Ctlcontrols()方法:
this.Media.get_Ctlcontrols().stop();
Run Code Online (Sandbox Code Playgroud)
我不知道为什么会出现这个错误.任何人都可以解释我以及如何解决这个问题?
看起来您正试图通过显式调用其get方法来访问属性.
试试这个(注意get_并且()缺少):
this.Media.Ctlcontrols.stop();
Run Code Online (Sandbox Code Playgroud)
这是一个关于属性如何在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());
}
}
Run Code Online (Sandbox Code Playgroud)