• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Jeanne Boyarsky
  • Bear Bibeault
Sheriffs:
  • Rob Spoor
  • Henry Wong
  • Liutauras Vilda
Saloon Keepers:
  • Tim Moores
  • Carey Brown
  • Stephan van Hulst
  • Tim Holloway
  • Piet Souris
Bartenders:
  • Frits Walraven
  • Himai Minh
  • Jj Roberts

Need help with debugging error CS0165 on C#

 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi there, I am new to this forum and was referred to here by a kind redditor so I decided to come here to ask my question, basically, I was trying to make a to-do list console app using Java C#, however, while trying to use a string variable in a switch statement, I ran into error CS0165 which states that I am using an unassigned local variable. What does this error mean and how do I fix it?
PS: Here's the code from the program I was trying to write, I ran into an error at around the last line, would really appreciate any help or advice asap
class Program
   {
       static void Main(string[] args)
       {

           //booleans to be used

           bool newtask;
           bool completetask;
           bool motivateme;
           bool addquote;
           bool incompletedtasklist;
           bool incompletedtasknum;
           bool completedtasklist;
           bool completedtasknum;
           bool help;
           bool oops;





           //all variables to be used

           Int32 IncompletedTaskNum;
           Int32 CompletedTaskNum;
           string IncompletedTaskNames;
           string CompletedTaskNames;
           string MotivationalQuotes;
           string OopsQuotes;
           string CommandName;
           string NewTask = "newtask";

       


           //procedures for program

           Console.WriteLine("Hello User, what would you like to do today?");

           CommandName = Console.ReadLine();

           //if (CommandName == "newtask")
           //{
               //newtask = true;
           //}

           switch(CommandName)
           {
               
               case "newtask":
                   newtask = true;
                   Console.WriteLine("Please enter the name of this task.");
                   IncompletedTaskNames = Console.ReadLine();
                   break;
               case "completetask":
                   completetask = true;
                   Console.WriteLine("Please enter the name of the task that you have completed.");
                   CompletedTaskNames = Console.ReadLine();
                   break;
               case "motivateme":
                   motivateme = true;
                   Console.WriteLine("You can do it!");
                   Console.ReadLine();
                   break;
               case "addquote":
                   addquote = true;
                   Console.WriteLine("Please enter the quote that you would like to add.");
                   MotivationalQuotes = Console.ReadLine();
                   break;
               case "incompletedtasklist":
                   incompletedtasklist = true;
                   Console.WriteLine(IncompletedTaskNames);
                   break;






           }


       }





   }      


       
   }
 
Can't .... do .... plaid .... So I did this tiny ad instead:
SKIP - a book about connecting industrious people with elderly land owners
https://coderanch.com/t/skip-book
reply
    Bookmark Topic Watch Topic
  • New Topic