Petit Computer Wiki:Chat/Logs/17 November 2013

 [11:55]  Click. [11:55]  dangit [11:55]  who here [11:55]  would love [11:55]  an rpg maker like system for ptc [11:56]  I'm trying to make the "Detect string or variable" program in C#, but it keeps throwing exceptions with Convert.ToInt32 and Convert.ToString [11:56]  My internet is acting up [11:56]  hmm... I think I would. Probably wouldn't use it myself [11:56]  You don't need "Convert.ToString", just use .ToString on the variable in question [11:57]  I don't know about the other one, it could be that you have poorly formed strings [11:57]  here's my code [11:57]  using System; [11:57]  [11:57]  class Program [11:57]  { [11:57] <IAmAPersson> public static void Main(String[] args) [11:57] <IAmAPersson> { [11:57] <IAmAPersson> Console.Write("Enter a string or a variable, and I will figure out which one it is!\n"); [11:57] <IAmAPersson> string inp = Console.ReadLine; [11:57] <IAmAPersson> if (Convert.ToString(Convert.ToDouble(inp)) == inp) [11:57] <IAmAPersson> { [11:57] <IAmAPersson> Console.Write("You entered a variable!\n"); [11:57] <IAmAPersson> } [11:57] <IAmAPersson> else [11:57] <IAmAPersson> { [11:57] <IAmAPersson> Console.Write("You entered a string!\n"); [11:57] <IAmAPersson> } [11:57] <IAmAPersson> Console.ReadKey; [11:57] <IAmAPersson> } [11:57] <IAmAPersson> } [11:57] <IAmAPersson> [11:57] <IAmAPersson> it works fine until you enter anything with letters [11:57] <Randomouscrap98> Oh, that's why [11:57] <Randomouscrap98> You need the "TryParse" method, not just straight up conversion [11:57] <IAmAPersson> I know why it's acting up [11:57] <IAmAPersson> oh [11:58] <Randomouscrap98> You only use Convert if you KNOW what the input will be [11:58] <Randomouscrap98> In your program, you don't, so you "Try" to parse it [11:58] <Randomouscrap98> http://msdn.microsoft.com/en-us/library/f02979c7(v=vs.110).aspx [11:58] <Randomouscrap98> If it can parse it as an integer (or double, if you want), then it's an integer. Otherwise it's a string