C# cannot convert method to non delegate type

后端 未结 7 1831
猫巷女王i
猫巷女王i 2020-12-08 07:12

I have a class called Pin.

public class Pin
{
    private string title;

    public Pin() { }

    public setTitle(string title) {
        this.         


        
7条回答
  •  甜味超标
    2020-12-08 07:14

    Because getTitle is not a string, it returns a reference or delegate to a method (if you like), if you don't explicitly call the method.

    Call your method this way:

    string t= obj.getTitle() ; //obj.getTitle()  says return the title string object
    

    However, this would work:

    Func method = obj.getTitle; // this compiles to a delegate and points to the method
    
    string s = method();//call the delegate or using this syntax `method.Invoke();`
    

提交回复
热议问题