asp.net - Constraints are not allowed on non-generic declarations when define delegate
问题描述
I want to define delegate
as the following:
public delegate void DataRequestingEventHandler(object sender,
CommandEventArgs e) where Entity : IEntityId<EntityKey>, new() where
EntityKey : IEntityKey, new();
But I am receiving this error:
Constraints are not allowed on non-generic declarations
Any ideas?
thanks
解决方案
That's because Constraints are not allowed on non-generic declarations. So you need to add Generic Type Parameters to your declaration to make it a generic declaration.
Looks like you intended Entity
and EntityKey
to be generic type parameters, but failed to declare them. Also by convention generic type parameters start with T
, eg:
public delegate void DataRequestingEventHandler<TEntity, TEntityKey>(object sender, CommandEventArgs e)
where TEntity : IEntityId<TEntityKey>, new() where TEntityKey : IEntityKey, new();
推荐阅读
- javascript - 无法读取未定义的属性“nsfw”-discord.js
- python - Python:在 txt 文件中添加时间
- amazon-web-services - 将 ant 与 AWS CodeBuild 一起使用 - build.xml 不存在以及新手的其他问题
- python - 无法从 url 读取压缩文件
- symfony - 我可以在 symfony 4 中使用这个表单吗?
- jquery - jquery On Click AJAX 只触发一个结果
- excel - 像 t-sql 中的 excel 格式单元格一样转换日期时间中的字符串
- javascript - Pako js在膨胀后返回无效结果
- r - 不能将负二项式回归拟合到日志数据
- python - 安装 Django 虚拟环境的问题