none
what is events data type RRS feed

  • Question

  • first question:Is this true that events(like KeyPress,Click,Double Click and etc) is delegate data types?

    second question:  Is this true that have no usable events in console projects(just in itself not in Win form ,WPF or etc)?


    • Edited by Reza1992 Saturday, February 15, 2020 9:14 PM
    Saturday, February 15, 2020 9:14 PM

Answers

  • Events are declared based on delegates. For example, you can declare an event like this:

    public delegate void MyDelegateType(MyType myArgument);
    public event MyDelegateType MyEvent;
    

    So yes, you use a delegate as the type for the event.

    As to the Console application, you can always write the application using your own classes that fire your own events and handle these events in other classes of your own. All of them can be hosted in a Console application.

    Apart from your own events, I can think of at least one built-in event that is useful in a Console application: AppDomain.UnhandledException

    https://docs.microsoft.com/en-us/dotnet/api/system.appdomain.unhandledexception?view=netframework-4.8

    There are also other classes such as SerialPort that fire events and can be used in a Console application.

    • Marked as answer by Reza1992 Saturday, February 15, 2020 10:32 PM
    Saturday, February 15, 2020 10:28 PM
    Moderator

All replies

  • Events are declared based on delegates. For example, you can declare an event like this:

    public delegate void MyDelegateType(MyType myArgument);
    public event MyDelegateType MyEvent;
    

    So yes, you use a delegate as the type for the event.

    As to the Console application, you can always write the application using your own classes that fire your own events and handle these events in other classes of your own. All of them can be hosted in a Console application.

    Apart from your own events, I can think of at least one built-in event that is useful in a Console application: AppDomain.UnhandledException

    https://docs.microsoft.com/en-us/dotnet/api/system.appdomain.unhandledexception?view=netframework-4.8

    There are also other classes such as SerialPort that fire events and can be used in a Console application.

    • Marked as answer by Reza1992 Saturday, February 15, 2020 10:32 PM
    Saturday, February 15, 2020 10:28 PM
    Moderator
  • Thanks a lot
    Saturday, February 15, 2020 10:33 PM