C# 使用泛型类型列表编译错误CS0305
而C# 使用泛型类型列表编译错误CS0305,c#,sql-server,clr,csc,mscorlib,C#,Sql Server,Clr,Csc,Mscorlib,而csc/t:library strconcat.cs与一起使用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 pre
csc/t:library strconcat.cs
与一起使用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)
strconcat.cs(9,17):错误CS0305:使用泛型类型
“System.Collections.Generic.List”需要“1”类型参数
mscorlib.dll:(与先前错误相关的符号位置)
.cs代码取自:使用公共语言运行库。
我查了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);
}
}
}
使用系统;
使用System.Collections.Generic;
使用System.Data.SqlTypes;
使用System.IO;
使用Microsoft.SqlServer.Server;
[可序列化]
[SqlUserDefinedAggregate(Format.UserDefined,MaxByteSize=8000)]
公共结构strconcat:IBinarySerialize{
私有列表值;
公共void Init(){
this.values=新列表();
}
公共无效累积(SqlString值){
this.values.Add(value.value);
}
公共无效合并(strconcat值){
this.values.AddRange(value.values.ToArray());
}
公共SqlString终止(){
返回新的SqlString(string.Join(“,”,this.values.ToArray());
}
公共无效读取(二进制读取器r){
int itemCount=r.ReadInt32();
this.values=新列表(itemCount);
对于(int i=0;i与对应的文章中解释的错误-类型参数的数量不匹配
在您的例子中,当类型参数为:newlist()
和相应的字段定义私有列表值;
时,可以使用零类型参数调用newlist()
注意:如果您出于某种奇怪的原因想要非泛型版本,则相应的类名为ArrayList
,但泛型List
更易于使用和更安全。问题如前所述,您尚未指定要存储在列表中的类型。请按如下所示更改此部分
private List<string> values;
public void Init()
{
this.values = new List<string>();
}
私有列表值;
公共void Init()
{
this.values=新列表();
}
C#中的泛型类型要求指定它们用来代替System.Collections.Generic.List的类型,在这种情况下,它似乎是SqlString,因此请按如下方式更改代码的以下部分:
private List<SqlString> values;
public void Init() {
this.values = new List<SqlString>();
}
私有列表值;
公共void Init(){
this.values=新列表();
}
列表正在存储string
而不是SqlString
。