How to declare generic event for generic delegate in c#

后端 未结 6 1989
不思量自难忘°
不思量自难忘° 2020-12-17 16:55

I have a user control which deals with fileupload. I have defined a delegate as follows

public delegate void FileUploadSuccess(T value,FileUploadTyp         


        
6条回答
  •  春和景丽
    2020-12-17 17:34

    Why do you need a generic event? Can't you just use a normal event:

    public delegate void FileUploadSuccess(object value);
    

    and then

    public event FileUploadSuccess Success;
    

    In the Success event handler you will know the type of the object being passed:

    public void SuccessHandler(object value)
    {
        // you know the type of the value being passed here
    }
    

提交回复
热议问题