How to declare generic event for generic delegate in c#

后端 未结 6 2004
不思量自难忘°
不思量自难忘° 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:21

    That's impossible unless you define your type parameter in an enclosing class. For example:

    public delegate void FileUploadSuccess(T value, FileUploadType F)
    
    public class FileUploader
    {
        public event FileUploadSuccess FileUploaded;
    }
    

    But this only moves your problem to another location, since now you would have to declare two instances of the FileUploader class:

    FileUploader stringUploader = new FileUploader();
    FileUploader stringUploader = new FileUploader();
    

    This may not be what you want.

提交回复
热议问题