首页 > 解决方案 > 列出清单的最简单方法

问题描述

在做了一些搜索之后,似乎:

repeated type thislist = 1;

应该列出一个清单,但我收到了这个错误:

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

难道我做错了什么?

标签: c#protocol-buffers

解决方案


我将假设您使用的是 Google 实现,在这种情况下,您得到的是一种列表(an 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>();

where-as protoc (Google) 给出:

[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
public pbc::RepeatedField<global::type> Thislist {
    get { return thislist_; }

推荐阅读