Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/292.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/sql-server/24.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 使用泛型类型列表编译错误CS0305_C#_Sql Server_Clr_Csc_Mscorlib - Fatal编程技术网

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