How to make a list of string within list in C#

Hi Everyone,

I am new to Unity and I used to program in python.

I want to make a list of string within a list for example:

mylist = [[‘tom’,‘1’],[‘john’,‘2’],[‘jane’,‘3’]]
so mylist[0] would be [‘tom’,‘1’] and mylist[0][0] would be ‘tom’.


There are a few things diffrent in C# and python but I think you mean something else when you ask for a list. First to handle “Lists” you need to use system generic, like include in python (if I remember correctly)
Yes you can have a list of lists and that would look like this,

List<List<string>> crazyListOfStrings = new List<List<string>>(); 

But I would not suggest that.

This is how you create a list in untiy:

using System;
using System.Collections.Generic;

List<string> names = new List<string>();
//If you wanted to append to the top of the list
//Now the list contains
//names[0] == "Tom"
//names[1] == "Tom2"

But what I think you are looking for is a dictionary and that is almost the exact same way:

using System;
using System.Collections.Generic;

class Program
    static void Main()
	Dictionary<string, int> dictionary =
	    new Dictionary<string, int>();

	dictionary.Add("Tom", 2);
	dictionary.Add("Toms dad", 1);
	dictionary.Add("Toms mom", 0);
	dictionary.Add("Toms kinky boyfriend", -1);