Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
255 views
in Technique[技术] by (71.8m points)

c# - Input string was not in a correct format Int32.Parse

Getting the error, when trying to execute this line:

spellPrefabs[Int32.Parse(spell.spellName)]

spell.spellName is a string equal to "0"

Can't get it, why is it not working. Any ideas? Am I just dumb and miss something obvious?

enter image description here

question from:https://stackoverflow.com/questions/65647124/input-string-was-not-in-a-correct-format-int32-parse

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

Double-check that spell.spellName.Length is 1 and (int)spell.spellName[0] is 0x30. The debugger display might not show all the characters that are actually in the string.

If the string is from user input it might be a good idea to be prepared for such incorrectly formed input by either catching the exception or using int.TryParse.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...