I am trying to create a tree structure using string arrays. I'm hoping to get the structure looking like this:
-UK
--Cars
---SUV
----Range Rover
---Saloon
----Jaguar
From these arrays
string[] suv = new string[] {"UK","Cars","SUV","Range Rover"};
string[] saloon = new string[] {"UK","Cars","Saloon","Jaguar"};
I have a ViewModel for the tree structure implementation:
public class TransportViewModel
{
public string Name { get; set; }
public ObservableCollection<TransportViewModel> TransportItems { get; set; }
}
The issue I have is that I don't know how to dynamically nest the items in the string array. I was trying to loop through the array elements and do something there but I don't know what to do to get the tree structure. Can anyone help please?
public static void CreateTree(string[] transportArray)
{
foreach(var item in transportArray)
{
// some TransportViewModel.Add implementation here??
}
}