C# 方法无法显式调用运算符或访问器
我添加了.dll:C# 方法无法显式调用运算符或访问器,c#,C#,我添加了.dll:AxWMPLib并使用方法get\u Ctlcontrols(),但它显示了如下错误: AxWMPLib.AxWindowsMediaPlayer.Ctlcontrols.get':无法显式调用运算符或访问器 这是我使用get\u Ctlcontrols()方法编写的代码: this.Media.get_Ctlcontrols().stop(); 我不知道为什么会出现这个错误。有人能解释一下我和如何解决这个问题吗?看起来您正试图通过显式调用属性的get方法来访问属性 尝试此操
AxWMPLib
并使用方法get\u Ctlcontrols()
,但它显示了如下错误:
AxWMPLib.AxWindowsMediaPlayer.Ctlcontrols.get':无法显式调用运算符或访问器
这是我使用get\u Ctlcontrols()
方法编写的代码:
this.Media.get_Ctlcontrols().stop();
我不知道为什么会出现这个错误。有人能解释一下我和如何解决这个问题吗?看起来您正试图通过显式调用属性的get方法来访问属性 尝试此操作(请注意,
get\uu
和()
丢失):
下面是一个关于属性在C#中如何工作的小示例-只是为了让您理解,这并不假装准确,所以请阅读比这更严肃的内容:)
谢谢你提出这个问题,伊恩,通过搜索引擎可以很容易地搜索到这个问题,保罗的答案非常笼统,很多搜索类似答案的人都能得到快速的帮助。使用反射时,请获取。。。表单在typeof(path.to.MyClass).GetMethods(BindingFlags)的输出中返回
this.Media.Ctlcontrols.stop();
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());
}
}