列出清单的最简单方法

时间:2018-07-05 18:37:13

标签: c# protocol-buffers

进行一些搜索后,好像:

repeated type thislist = 1;

应该列出一个列表,但出现此错误:

  

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

我做错什么了吗?

2 个答案:

答案 0 :(得分:2)

我将假设您使用的是Google实现,在这种情况下,您得到的是列表的类型IList<T>)而不是{{1} }。

如果您想要简单的惯用类型,protobuf-net可能更适合您; you can see the difference here(单击“生成”,然后在List<T>(protogen) C#之间更改工具-protogen(protobuf-net)提供:

(protoc) C#

where-protoc(Google)给出:

[global::ProtoBuf.ProtoMember(1)]
public global::System.Collections.Generic.List<type> thislist { get; }
    = new global::System.Collections.Generic.List<type>();

答案 1 :(得分:0)

如果未使用标准.net库,则可能无法正常工作,但通常使用以下方式列出列表:

var listName = new List<type>();

类型是您的变量,即整数,字符串等

如果没有帮助,请忽略,但我想我也应该提一下。

关于, 阴影

相关问题