I am new to C# Programming and I don't know How to convert list to dictionary and vice versa and I am getting an runtime error called " StackOverflowException." Can anyone help me out or if anyone knows the solution please let me know.
Thanks in advance.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Assign2
{
class Conversion
{
}
class Program
{
static void Main(string[] args)
{
Conversion conversion = new Conversion();
var list = new List<string> { "Demo1","Demo2","Demo3","Demo4"};
var dictionary = conversion.ListToDictionary(list);
foreach (var item in dictionary)
{
Console.WriteLine($"{item.Key}, {item.Value}");
}
var convertedList = conversion.DictionaryToList(dictionary);
foreach (var item in convertedList)
{
Console.WriteLine($"{item}");
}
Console.ReadLine();
}
}
}