c# - 编译错误CS0305 使用泛型类型List

标签 c# sql-server clr csc mscorlib

csc/t:library strconcat.csusing 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/

相关文章:

c# - 有没有一种灵活的方式来部署我的 silverlight 应用程序并以编程方式更改设置?

C# 编程作业

c# - 如何在 C# 中的 FontWeights 之间使用等于运算符?

.net - 根源是什么?

c# - 将日期时间值更新到具有奇怪格式的数据库中显示不正确的日期

mysql - SQL 查询,获取具有所需技能表中所有技能的机械师的所有姓名

sql-server - 如何使用 ssis 将检索到的行插入到另一个表中

sql-server - 如何撤消 sp_addlinkedserver abc ,'SQL Server' ?

c# - 为什么 CLR 会重新抛出 ThreadAbortException?

.net - .NET 中 API 突破性更改的权威指南