WinForm events in another class .NET2 Simplify delegate

前端 未结 1 414
忘了有多久
忘了有多久 2021-01-17 03:21

Any way to make this working code simpler ie the delegate { }?

 public partial class Form1 : Form
{
    private CodeDevice codeDevice;

    public Form1()
           


        
相关标签:
1条回答
  • 2021-01-17 03:43

    If don't think you could simplyfy:

    public event EventHandler ConnectionSuccessEvent = delegate { }
    

    even in c#3 + you could only do

    public event EventHandler ConnectionSuccessEvent = () => { }
    

    However you could simplify

    codeDevice.ConnectionSuccessEvent += new EventHandler(SetupDeviceForConnectionSuccessState);
    

    to

    codeDevice.ConnectionSuccessEvent += SetupDeviceForConnectionSuccessState;
    
    0 讨论(0)
提交回复
热议问题