You are trying to pair up parent and its child, I think using List to contain pairs of
key value[
^] would be more suitable to capture this relationship. Check out this example:
using System;
using System.Collections.Generic;
public class Program
{
public static void Main()
{
string str = "parent/parent2/parent3/parent4/child";
if(str.Contains("/")){
string[] persons = str.Split('/');
var kinship = new List<KeyValuePair<string, string>>();
for(int i=0; i < persons.Length; i++){
string parent = persons[i];
string child = i < persons.Length-1? persons[i+1]: "nil";
kinship.Add(new KeyValuePair<string, string>(parent, child));
Console.WriteLine("parent: {0}, child: {1}\n", parent, child);
}
}
}
}