working on a project where I'm making a "blog" that puts the blog posts in to a string array that then gets transferred to a list array. This is my current code and I'd appreciate any help. I'm still new to c# and programming as a whole so unsure how to fix it.
The current problem is that in case 3 I get the error message : Operator '==' cannot be applied to operands of type 'string' and 'string[]' and the name "i" does not exist in the current context of the "the post is in the blog" codeblock.
I created a minimal reproducible example here and the only other functions the program otherwise has is to 1. Delete all blogposts and 2. to print out all blogposts with their name and content.
bool minBool = true;
List<string[]> blogPost = new List<string[]> { };
string[] post = new string[2];
while (minBool)
{
Console.WriteLine("\n\n\tWelcome to the blog!");
Console.WriteLine("\n\t[1] - Write a blogpost");
Console.WriteLine("\t[3] - Search for a blogpost");
Console.Write("\n\tChoice:");
Int32.TryParse(Console.ReadLine(), out int input);
switch (input)
{
case 1:
Console.Write("\tName your post: ");
post = new string[2];
post[0] = Console.ReadLine();
Console.Write("\tWrite your post: ");
post[1] = Console.ReadLine();
blogPost.Add(post);
break;
case 3:
string searchTerm = Console.ReadLine();
string result = "The blogpost doesn't exist";
foreach (string blog in blogPost)
{
if (searchTerm == blog)
{
result = $"\tThe post is in the blog: {post[i]}";
break;
}
}
Console.WriteLine(result);
break;