В рамках данной задачи предлагаю использовать Newtonsoft.
Установить пакет можно через NuGet в вижле.
class Program
{
const string pathData = @"c:\data.dat";
static void Main(string[] args)
{
WriteData(GenerateData());
DisplayListData(ReadData());
Console.ReadLine();
}
static List<Cell> GenerateData()
{
List<Cell> dataCell = new List<Cell>();
for (int i = 1; i <= 5; i++)
{
int val = i * 10;
Cell cell = new Cell()
{
neighbors = new List<int>() {val, val + 1, val + 2},
index = i
};
dataCell.Add(cell);
}
return dataCell;
}
static void WriteData(List<Cell> dataCell)
{
using (StreamWriter file = File.CreateText(pathData))
{
JsonSerializer serializer = new JsonSerializer();
serializer.Serialize(file, dataCell);
}
Console.WriteLine("Save Data in PATH: " + pathData);
}
static List<Cell> ReadData()
{
using (StreamReader file = File.OpenText(pathData))
{
JsonSerializer serializer = new JsonSerializer();
return (List<Cell>) serializer.Deserialize(file, typeof(List<Cell>));
}
}
static void DisplayListData(List<Cell> dataList)
{
Console.WriteLine(new String('-', 5));
foreach (var cell in dataList)
{
Console.WriteLine("Cell index: " + cell.index);
Console.WriteLine(new String('-', 5));
for (int i = 0; i < cell.neighbors.Count; i++)
{
Console.WriteLine("Value index: " + i + " = " + cell.neighbors[i].ToString());
}
Console.WriteLine(new String('-', 5));
}
}
}
[Serializable]
public class Cell
{
public List<int> neighbors { get; set; }
public int index { get; set; }
}
Думаю общий принцип понятен.