I\'d like to set up a multidimensional list. For reference, I am working on a playlist analyzer.
I have a file/file-list, which my program saves in a standard list.
Here's a little something that I made a while ago for a game engine I was working on. It was used as a local object variable holder. Basically, you use it as a normal list, but it holds the value at the position of what ever the string name is(or ID). A bit of modification, and you will have your 2D list.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace GameEngineInterpreter
{
public class VariableList
{
private List list1;
private List list2;
///
/// Initialize a new Variable List
///
public VariableList()
{
list1 = new List();
list2 = new List();
}
///
/// Set the value of a variable. If the variable does not exist, then it is created
///
/// Name or ID of the variable
/// The value of the variable
public void Set(string variable, T value)
{
if (!list1.Contains(variable))
{
list1.Add(variable);
list2.Add(value);
}
else
{
list2[list1.IndexOf(variable)] = value;
}
}
///
/// Remove the variable if it exists
///
/// Name or ID of the variable
public void Remove(string variable)
{
if (list1.Contains(variable))
{
list2.RemoveAt(list1.IndexOf(variable));
list1.RemoveAt(list1.IndexOf(variable));
}
}
///
/// Clears the variable list
///
public void Clear()
{
list1.Clear();
list2.Clear();
}
///
/// Get the value of the variable if it exists
///
/// Name or ID of the variable
/// Value
public T Get(string variable)
{
if (list1.Contains(variable))
{
return (list2[list1.IndexOf(variable)]);
}
else
{
return default(T);
}
}
///
/// Get a string list of all the variables
///
/// List string
public List GetList()
{
return (list1);
}
}
}