【问题标题】:Cannot convert string to Type (enum) c# [duplicate]无法将字符串转换为类型(枚举)c# [重复]
【发布时间】:2015-11-09 14:49:01
【问题描述】:

我正在搞乱我玩的游戏的源代码,我正在制作游戏内命令,但我遇到了问题。

public enum WeatherType
{
    None = 1,
    Rain = 2,
    Snow = 3,
    RainWind = 4,
    AutumnLeaves = 5,
    CherryBlossomPetals = 7,
    CherryBlossomPetalsWind = 8,
    BlowingCotten = 9,
    Atoms = 10
}     

GC.MyClient.SendPacket(General.MyPackets.Weather(Splitter[1], Convert.ToUInt32(Splitter[2]), Convert.ToUInt32(Splitter[3]), Convert.ToUInt32(Splitter[4])));

错误出现在 Splitter[1] 上,它显示“无法将字符串转换为 WeatherType”。 有谁知道如何解决这一问题?因为我真的很难过。谢谢

【问题讨论】:

  • 在这种情况下,您必须将其类型转换为 WeatherType
  • 向我们展示Splitter 包含什么以及General.MyPackets.Weather 期望/做什么可能会有所帮助

标签: c# string enums converter


【解决方案1】:

就像你在所有情况下所做的那样

将此添加到您的代码中,它将为您工作

Convert.ToUInt32(Splitter[1])

【讨论】:

    猜你喜欢
    • 2011-01-01
    • 2021-07-21
    • 2012-12-07
    • 2013-01-23
    • 1970-01-01
    • 2018-02-14
    • 2019-02-21
    相关资源
    最近更新 更多