Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Method cannot explicitly call operator or accessor

Tags:

c#

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

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

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?

like image 507
lan Avatar asked Jul 19 '26 05:07

lan


1 Answers

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

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

this.Media.Ctlcontrols.stop();

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

    }

}
like image 192
Paolo Tedesco Avatar answered Jul 20 '26 18:07

Paolo Tedesco



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!