Answer the question
In order to leave comments, you need to log in
Implicit conversion from void to user method. What's my mistake?
Good afternoon, I ran into the problem of implicit type conversion, but I can’t understand why it occurs, because everything seems to be correct. Please explain what is my mistake or show the correct execution.
на C#
public int PlayerReady;
delegate void UI();
class OnReady
{
public event UI ReadyEvent;
public void OnReadyEvent()
{
ReadyEvent();
}
}
class UserReady
{
bool uiReady;
public UserReady(bool Ready)
{
this.Ready = Ready;
}
public bool Ready { set { uiReady = value; } get { return uiReady; } }
public void OnReadyHandler(int PlayerReady)
{
WriteLine("событие вызвано!\n");
EventPlus(ref PlayerReady);
}
void EventPlus (ref int PlayerReady) {
PlayerReady++;
}
}
class Program
{
static void Main()
{
var evt = new OnReady();
var UR = new UserReady(ready);
evt.ReadyEvent += UR.OnReadyHandler(server.PlayerReadyToGame);//тут ошибка "Не удается неявно преобразовать тип void в Example.UI"
}
}
Answer the question
In order to leave comments, you need to log in
evt.ReadyEvent += UR.OnReadyHandler(server.PlayerReadyToGame);
<ClassOrObject>.<EventName> += <ClassWhoseMethodShouldRun>.<Method MatchedBy Signature>
You have a delegate signature delegate void UI();
that is different from a method signature public void OnReadyHandler(int PlayerReady)
. The signature of the delegate must be void (int)
in this case.
The magic is most likely that third-party comments first await the approval of the site owner. Go and see what you have in them. :)
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question