I took C# in college back in 2010 and wanted to get back into programming so I have been self teaching again. I wrote the following code working through a tutorial on enum but I wanted to figure out how to convert input string to integer so I can pass the argument to a switch command. I wrote the code until I got it to work then searched the internet for solutions and it seems my solution is not really common so just looking for some feedback on if this is a bad way to complete the task I was going for or not.
Thanks to anyone willing to give input. Remember I am relearning and do not program for a career, although that would be a dream.
Thanks to anyone willing to give input. Remember I am relearning and do not program for a career, although that would be a dream.
Code for console app:
using System;
namespace Program
{
public class TreeSales
{
public enum Tree
{
Apple = 1,
Oak,
Orange
}
static void Main()
{
Tree treeType = Tree.Apple;
Console.WriteLine("Please pick an option from below on what type of tree you would like information about:");
Console.WriteLine("Options:\n" +
"1.Apple\n" +
"2.Oak\n" +
"3.Orange");
string conInput = Console.ReadLine();
Convert.ToInt32(conInput);
if (Convert.ToInt32(conInput) == 1)
{
treeType = Tree.Apple;
}
else if (Convert.ToInt32(conInput) == 2)
{
treeType = Tree.Oak;
}
else if (Convert.ToInt32(conInput) == 3)
{
treeType = Tree.Orange;
}
switch (treeType)
{
case Tree.Apple:
Console.WriteLine("Apple");
break;
case Tree.Oak:
Console.WriteLine("Oak");
break;
case Tree.Orange:
Console.WriteLine("Orange");
break;
}
}
}
}