I am trying to make a program that works as a logbook. The only problem I'm facing so far is the search function where the user should be able to search for a post, and then it prints it out. I am not sure what I have done wrong, and I have been looking through many posts. For your information the whole logbook is a list while every post is an array in this list. The search function is in case 3. The program is compiling, but the problem is when I search for an old post, then it only prints out System.String[]. I should also add that I want both the title and post connected to the title to be printed out when the user searches for the title of the post.
here is the code:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
namespace Loggbok
{
class MainClass
{
public static void Main(string[] args)
{
bool running = true;//Ger ett booleskt värde till variabeln running för att kunna skapa en loop
List<string[]> loggbok = new List<string[]>();
// int loggIndex = 0; // Används för att fylla Arrayen
while (running)//Här skapas loopen
{
Console.WriteLine("\nVälkommen till loggboken!");
Console.WriteLine("\n[1] Skriv ett inlägg");
Console.WriteLine("[2] Skriv ut alla inlägg");
Console.WriteLine("[3] Sök inlägg");
Console.WriteLine("[4] Avsluta loggboken");
Console.Write("\nVälj: ");
int option;
try
{
option = Int32.Parse(Console.ReadLine());
}
catch
{
Console.WriteLine("Fel, du får bara skriva in nummer");
continue;
}
switch (option)
{
case 1:
string[] logg = new string[2];
Console.WriteLine("Ange en Titel");
logg[0] = Console.ReadLine();
Console.Clear();
Console.WriteLine("Ange text");
logg[1] = Console.ReadLine();
loggbok.Add(logg);
break;
case 2:
foreach (string[] item in loggbok)
{
Console.WriteLine(item[0]);
Console.WriteLine(item[1]);
}
Console.ReadLine();
break;
case 3:
Console.WriteLine("Skriv in ett ord du vill söka efter i loggboken");
var nyckelord = Console.ReadLine();
var entries = loggbok.Where(entry => entry.Contains(nyckelord));
foreach (var entry in entries)
{
Console.WriteLine(entry);
}
if (entries.Count() == 0)
{
Console.Write("Din sökning misslyckades...");
}
break;
case 4:
running = false;
break;
}
}
}
}
}