Click here to Skip to main content
15,917,059 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
C#
   List<string> loggbok = new List<string> { };
   DateTime datum = DateTime.Now;
   Console.WriteLine(datum);

   string titel = "";
   string logg = "";
   string sparad = "";

   bool isRunning = true;
   while (isRunning)
       try
       {
           {
               Console.WriteLine("\n\t Välkommen till loggboken");

               Console.WriteLine("\n\t[1] Skriv nytt inlägg i loggboken\n" +
                                 "\t[2] Sök inlägg i loggboken\n" +
                                 "\t[3] Skriv ut alla loggar" +
                                 "\t[4] Avsluta programmet");
               Console.Write("\tVälj: ");

               int menyVal = Convert.ToInt32(Console.ReadLine());

               switch (menyVal)
               {
                   case 1:
                       Console.Clear();
                       Console.Write("Skriv titel på ditt inlägg: ");
                       titel = Console.ReadLine();
                       Console.Write("Skriv ditt inlägg: ");
                       Console.WriteLine(datum);
                       Console.WriteLine(titel);
                       Console.WriteLine(sparad);
                       sparad = Console.ReadLine();
                       Console.WriteLine("Alla dina inlägg är nu sparade!");
                       logg = datum + "\n" + titel + "\n" + sparad;

                       loggbok.Add(logg);
                       break;

                   case 2:
                       Console.Clear();
                       Console.WriteLine("Skriv in ett sökOrd");

                       var sökObjekt = Console.ReadLine();

                       var hittatItem = false;
                       foreach (var item in loggbok)
                       {
                           if (item.Contains(sökObjekt))
                           {
                               hittatItem = true;

                               Console.WriteLine(item);
                           }
                       }
                       if (!hittatItem)
                       {
                           Console.WriteLine("Felaktig inmatning...Vänligen försök igen!");
                       }
                       break;

                   case 3:
                       Console.Clear();
                       Console.WriteLine("HÄR ÄR ALLA DINA SPARADE INLOGG: ");
                       foreach (string loggboken in loggbok)
                       {
                           Console.WriteLine(loggboken);
                       }
                       Console.WriteLine("Tryck på valfri knapp på tangentbordet för att gå" +
                           " tillbaka till meny");
                       Console.ReadKey();
                       break;

                   default:

                       break;

                  case 4:
                       return;
               }
           }
       }

       catch
       {
           Console.Clear();
           Console.WriteLine("Nu blev det fel, gör ett val i menyn...");
       }
}


What I have tried:

The program is doing ok. All the required functions are working probably. So I just some improvement proposals. Feel free to point out even if something is wrong. Cause I'm beginner.
Posted
Comments
BillWoodruff 8-Nov-17 18:29pm    
Since I don't speak your language, what I can say is limited, but, I suggest you add a brief English language description to your post of what your program does.

There's obviously a lot of re-factoring you can do with the strings you use ... if that is important to you ?
Member 13510990 8-Nov-17 18:45pm    
My program must have a menu and I have to use Switch.
Secondly I have to use a list while each individual log should be an array.
BillWoodruff 8-Nov-17 22:00pm    
"use a list while each individual log should be an array."

The code I see now keeps one List of String. Is that not what you want ?

What about saving the Log ?
Richard MacCutchan 9-Nov-17 4:36am    
In case 1, you are writing fields to the console that have not any values.
Perić Željko 29-Nov-17 7:16am    
I wonder when this program is going to change state of isRunning variable to false and end.

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