最简单的方法创建一个列表

4

经过一些搜索,似乎:

repeated type thislist = 1;

我应该制作一个列表,但是出现了以下错误:

无法将“Google.Protobuf.Collections.RepeatedField”转换为“System.Collections.Generic.List”

我做错了什么吗?


您能提供一下获取那行代码的资源链接吗?它应该生成一个列表。 - takendarkk
它实现了 IListIList<T>,而不是从具体类 List 派生而来。(请参阅 https://developers.google.com/protocol-buffers/docs/reference/csharp/class/google/protobuf/collections/repeated-field-t-) - orhtej2
我认为这就是我检查的内容:https://dev59.com/w07Sa4cB1Zd3GeqP4IJl - Brian Park
1个回答

2
我假设您正在使用谷歌的实现,这种情况下您得到的是一个列表类型(IList<T>), 而不是List<T>
如果您想要简单的习惯用法类型,protobuf-net可能更适合您;您可以在这里看到区别(点击“生成”,并在(protogen) C#(protoc) C#之间更改工具 - protogen (protobuf-net) 给出:
[global::ProtoBuf.ProtoMember(1)]
public global::System.Collections.Generic.List<type> thislist { get; }
    = new global::System.Collections.Generic.List<type>();

而 protoc(Google)则给出:
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
public pbc::RepeatedField<global::type> Thislist {
    get { return thislist_; }

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接