C # fixes vs Python lists

0

In Python the lists could contain other lists for example

    lista = ["x",["a","b"],["c","d"],"z"];
print lista[1][1]>>>>>>>>>> output "b"   

my question is ... in c # can other fixes be contained in an array and contain loose elements such as "x" and "z" in the python list?

I was testing arraylist and when I use

miarreglo.AddRange(otro_arreglo);

what it does is put the elements together without separating them ie I hope I wait for this {"x", {"a", "b"}} BUT I get this {"x", "a", "b"}

    
asked by Shiki 30.04.2017 в 16:26
source

1 answer

1

It is complicated to compare a strongly typed language such as C# and Python which is a scripting language and is more flexible in these circumstances, however, you could get what you are looking for without problems in C# as well:

1.- Matrices ( MSDN - Matrices )

In C# you can have matrices that after all is an array of arrays.

int[,] matriz = { { 1, 2, 3 }, { 4, 5, 6 } };

2.- Lists ( MSDN - List )

You can use a list of arrays, and thus have your array of arrays:

List<int[]> lista_arrays = new List<int[]>();
lista_arrays.Add(new int[] { 1, 2, 3 });
    
answered by 30.04.2017 / 17:13
source