Click here to Skip to main content
15,885,132 members
Please Sign up or sign in to vote.
2.00/5 (1 vote)
See more:
Good Day Everyone

I need your help, I am writing a program that will return a certain result based on a
userinput, however I tested it and I keep getting the first case's result for both
first and second case.

C#
private void Button_Click_1(object sender, RoutedEventArgs e)
  {
      SpiderNames myspiders;
      string userInputTextBox = "";


      if (Enum.TryParse<SpiderNames>(userInputTextBox, true, out myspiders));
      {

      switch (myspiders)
      {
          case SpiderNames.Violen:

              string Violen = File.ReadAllText(@"C:\Users\Documents\Violen.txt");
              outPutTextBox.Text = Violen;

              break;

          case SpiderNames.Sacspider:

              string Sacspider = File.ReadAllText(@"C:\Users\Documents\Sacspider.txt");
              outPutTextBox.Text = Sacspider;

              break;
          case SpiderNames.Daddylonglegs:
              break;
          default:
              break;
Posted
Comments
Sergey Alexandrovich Kryukov 24-May-15 11:30am    
Use the debugger, and you will see. Don't hard-code spider's file names and never use hard-coded file locations.
—SA

1 solution

You set userInputTextBox to an empty string, so your function will parse an empty string. Instead, put the value of a text box in there, like this:
C#
userInputTextBox = yourTextBox.Text;
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900