简体   繁体   中英

method must have a return type pointing to NewCall Handler class in my code. What am i missing

In the class i am defining a method called NewCallHandler. Even though i am calling this function inside another method, but it gives me error: method must have return type .

class CallHandler
{

      public NewCallHandler(ICall call)
       {
        _call = call;
        _phoneCallAudioSender = new PhoneCallAudioSender();
        _phoneCallAudioSender.AttachToCall(call);
        _mediaConnector = new MediaConnector();
        _greetingMessageTimer = new Timer();
        _greetingMessageTimer.Elapsed += greetingMessageTimer_Elapsed;
        _greetingMessageTimer.Interval = 15000;
       }

here in this method of lowerMenu i am calling NewCallHandler function in the var variable

private void LowerMenu()
    {
        _call.CallStateChanged -= call_CallStateChanged;
        _call.DtmfReceived -= call_DtmfReceived;
        _greetingMessageTimer.Elapsed -= greetingMessageTimer_Elapsed;

        var  newCallHandler = NewCallHandler(_call);
        newCallHandler.BlindTransferNumber(_blindTransferNumber);
        newCallHandler.Completed += newCallHandler_Completed;
        newCallHandler.Start();
    }
}

i know this question has been asked before but can't find solution for my problem. Plz help me out in this matter. Thanks

it looks like you are defining a constructor, by the way you are instantiating class level variables inside your method. You even appear to do dependency injection, so I'm pretty sure this is intended to be a constructor.

A constructor name has to be the same name as the class. you should rename your constructor to:

public CallHandler(ICall call)

Then, you would call it with:

var callHandler = new CallHandler(_call);

notice the new keyword.

Besides constructors, all methods must have a return type. The compiler sees that your method isn't a constructor due to the name, assumes it's a normal method, and produces the error you see.

Methods have to have a return type declared or you have to use the keyword void if you don't want that method to return anything.

So change it to:

public void NewCallHandler(ICall call)

Are you expecting something from that method? If not you need to use void after public, otherwise you need put the type that you need to be returned.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM