当 csc/t:library strconcat.cs
与 using System.Collections.Generic;
时,我收到错误
strconcat.cs(9,17): error CS0305: Using the generic type
'System.Collections.Generic.List<T>' requires '1' type arguments
mscorlib.dll: (Location of symbol related to previous error)
.cs代码取自here :使用公共(public)语言运行时。
我检查了description在msdn上但是到现在还无法编译
using System;
using System.Collections.Generic;
using System.Data.SqlTypes;
using System.IO;
using Microsoft.SqlServer.Server;
[Serializable]
[SqlUserDefinedAggregate(Format.UserDefined, MaxByteSize=8000)]
public struct strconcat : IBinarySerialize{
private List values;
public void Init() {
this.values = new List();
}
public void Accumulate(SqlString value) {
this.values.Add(value.Value);
}
public void Merge(strconcat value) {
this.values.AddRange(value.values.ToArray());
}
public SqlString Terminate() {
return new SqlString(string.Join(", ", this.values.ToArray()));
}
public void Read(BinaryReader r) {
int itemCount = r.ReadInt32();
this.values = new List(itemCount);
for (int i = 0; i <= itemCount - 1; i++) {
this.values.Add(r.ReadString());
}
}
public void Write(BinaryWriter w) {
w.Write(this.values.Count);
foreach (string s in this.values) {
w.Write(s);
}
}
}
我正在使用 c:\Windows\Microsoft.NET\Framework\v2.0.50727
以及 c:\Windows\Microsoft.NET\Framework64\v2 运行 Windows 7 x64 .0.50727>
如何编译?抱歉,我刚刚开始使用 c# - 我在这里搜索了一些其他问题,这些建议对我来说没有取得进展(
最佳答案
对应于 CS0305 的文章中解释了错误- 类型参数的数量不匹配。
就您而言,您可以调用 new List()
当需要一个类型参数时,其类型参数为零,例如:new List<string>()
以及相应的字段定义private List<string> values;
.
注意:如果您出于某种奇怪的原因想要非通用版本,则相应的类名为 ArrayList
,但通用 List<T>
使用起来更简单、更安全。
关于c# - 编译错误CS0305 使用泛型类型List,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15242283/