C# 2.0 泛型下如何让 new T()调用构造函数时带参?

tfyuan123 tfyuan123 墨衍会员 · AI 创作全网分发 墨衍智能分发 通过墨衍一键同步至各平台 可同步平台 CSDN微信公众号微博知乎掘金百家号博客园抖音小红书 你的文章也可以这样分发 墨衍会员 ¥399起/年,写一次发全网 我也要 + 加入社区
在.NET 2.0 C# 代码如下:
public class note {
private string _value;

public note(string entervalue) {
_value = entervalue;
}
public string getvalue {
get { return _value; }
}
}

public class notes<T> {
string[] items = new string[2];

items[0] = "1";
items[1] = "2";

public T this[int index] {
get {
return new T(index); // <-- 这一步该如何编写?
}
}
}

在public class notes<T> 加入 where T : new() 这个能够调用默认的构造函数
但是无法加入参数的! public class notes<T> where T : new() {...}

求高人解答。
...全文
评论 6
收藏 已收藏
分享
返回顶部
tfyuan123
C# 111,129 成员 642,540 内容