简体   繁体   English

方法必须在我的代码中具有指向NewCall Handler类的返回类型。 我在想什么

[英]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. 在该类中,我定义了一个称为NewCallHandler的方法。 Even though i am calling this function inside another method, but it gives me error: method must have return type . 即使我在另一个方法中调用此函数,但它给我错误: 方法必须具有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 在lowerMenu的此方法中,我在var变量中调用NewCallHandler函数

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. 注意new关键字。

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. 方法必须声明一个返回类型,或者如果您不希望该方法返回任何内容,则必须使用关键字void。

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. 如果不是,则需要在公开后使用void,否则需要输入需要返回的类型。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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