We are supposed to put log entries (title and entry) in a sort of journal. That means having a list with each containing an array with room for two strings.
Now. We've worked with arrays and lists but never together.
Considering this is a school assignment I'm only asking for guidance to point me in the right direction.
So creating a list that on each entry contains space for an array of size 2. How should I think about this concept baring in mind I've only used them separately before?
A List<string[]> is a perfectly valid data structure, although a List<Tuple<string, string>> or a List<LogEntry> where LogEntry is a class with two string properties would be more idiomatic.
Note that there's not a declarative way to set the size of the underlying array (meaning that List<string[2]> is not a valid type.
Since you have to have a log title and entry, have you considered wrapping those in a separate class rather than using an array of two strings?
I mean doing something like this:
public class LogItem
{
public string Item;
public string Entry;
}
Then instead of having a list of arrays, you would just use a list of LogItem:
var myList = new List<LogItem>();
var myNewLogEntry = new LogItem {Title = "Entry title", Entry = "Entry message"};
myList.Add(myNewLogEntry);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With