c# - 列出清单的最简单方法
问题描述
在做了一些搜索之后,似乎:
repeated type thislist = 1;
应该列出一个清单,但我收到了这个错误:
无法从“Google.Protobuf.Collections.RepeatedField”转换为“System.Collections.Generic.List”
难道我做错了什么?
解决方案
我将假设您使用的是 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_; }
推荐阅读
- typescript - Firebase task.getResult().getData(); 总是返回 null。(异步问题?)
- swift - CoreData 聚合一对多关系
- python - 在 Lutz 的“Learning Python”中实现 ord() 背后的逻辑
- javascript - 不显示多个标记 MAP API
- android - BigPictureStyle 通知在 AndroidX 中不起作用
- python-3.x - 当我将 & 与 if 条件一起使用时,我的 python 代码不起作用;但是当我使用嵌套的 if 循环时,它工作正常
- python - Python 错误消息:TypeError:'str' 对象不可调用
- r - Stargazer 没有显示稳健 se 的观察次数
- r - 无法使用 R
- apache-kafka - 如何更改 Kafka Connect Source Connector 生成的主题名称