I'm trying to create a search method in C# and I am stuck.
This is my method that I want to use to search for the array values inside my List object:
public void Search()
{
Console.Write("\tKeyword: ");
string keyword = Console.ReadLine();
List<string> searchResults = new List<string>();
for (int a = 0; a < log.Count; a++)
{
foreach (string item in log[a])
{
if (item.Contains(keyword))
searchResults.Add(item);
}
}
Console.WriteLine("Search Results: ");
for (int b = 0; b < searchResults.Count; b++)
{
Console.WriteLine("\t{0}\t{1}\t\t{2}", searchResults[b][0], searchResults[b][1], searchResults[b][2]);
}
}
This is my List that I want to search through:
private List<string[]> log = new List<string[]>();
This is how I add arrays into the List:
string[] arrOfLog = new string[4] {
String.Format("{0:yyyy-MM-dd}", localDate),
title,
desc,
null
};
log.Add(arrOfLog);
What can I do to search for title and description values?
I get the exception:
Object reference not set to an instance of an object.