[英]Generic Interface in C# migrated from JAVA
I want to convert this interface members to C# 我想将此接口成员转换为C#
<T> T GetValue(string areaKey, string key, Class<T> clazz);
<T> T GetValue(string areaKey, string key, T defaultValue, Class<T> clazz);
but I am not so good with C# as with JAVA. 但是我对C#的了解不如对JAVA的了解。 Is it possible to use it in the same way as in JAVA? 是否可以以与JAVA中相同的方式使用它?
The generic type is just specified after the method name in C# 通用类型是在C#中的方法名称之后指定的
T GetValue<T> (string areaKey, string key, Class<T> clazz);
or, you can specify it on the interface itself: 或者,您可以在界面本身上指定它:
public interface IMyInterface<T>
{
T GetValue (string areaKey, string key, Class<T> clazz);
}
yup. 对。 You could try something like below: 您可以尝试以下操作:
public interface InterfaceName<T>
{
T GetValue(string areaKey, string key, T clazz);
T GetValue(string areaKey, string key, T defaultValue, T clazz);
}
Christos is correct, I would just add where T : class
Christos是正确的,我只想where T : class
public interface InterfaceName<T> where T : class
{
T GetValue(string areaKey, string key, T clazz);
T GetValue(string areaKey, string key, T defaultValue, T clazz);
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.