试图访问C#列表中的数据 [英] Trying to access the data in a list in C#
问题描述
我正在使用此API将消息从客户端发送到主机游戏。我知道主机在将它们打印到日志时收到消息bc它会根据我发送的数量增加或减少数量,但它不会给我里面的数据。只是给我列表的通用名称?包含数据。
这里定义了MPMessage: Stardew-Valley-Mods / MPMessage.cs at master·Platonymous / Stardew-Valley-Mods·GitHub [ ^ ]
I'm using this API to send a message from the client to the host game. I know the host is getting the messages bc when I print them to the log it will increase or decrease in number depending on how many I send, but it wont give me the data inside. Just gives me the generic name of the list? containing the data.
Here is where MPMessage is defined: Stardew-Valley-Mods/MPMessage.cs at master · Platonymous/Stardew-Valley-Mods · GitHub[^]
//receive Messages
List<MPMessage> clientMessage = PyNet.getNewMessages("MyMod.MyAddress").ToList();
foreach (object message in clientMessage)
this.Monitor.Log(message.ToString());
我的尝试:
也尝试使用地址而不是消息。它甚至都不接受它。
What I have tried:
Also tried using "address" instead of "message". It wouldn't even accept it.
推荐答案
你显示的MPMessage类没有显式实现ToString重载,这意味着它转移到了第一个类中。执行的继承层次结构:object
ToString的默认对象
实现返回名称该类的内容,而不是有关实例内容的任何有用信息。如果要使用内容记录单个字符串,则必须自己从MPMessage属性手动组装它。
The MPMessage class you show does not explicitly implement a ToString overload, which means it "devolves" to the first class in the inheritance hierarchy that does:object
And the defaultobject
implementation of ToString returns the name of the class, not any useful information about an instance's content. If you want to log a single string with the content you will have to manually assemble it from the MPMessage properties yourself.
这篇关于试图访问C#列表中的数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!