Hey every body
This is my method and the problem is the innerKey.Value
is struct
and in txt file just I have the name of struct not the struct content.
state
is nested Dictionary
where the object
is another Dictionary
.
How can i write struct content in my txt file?
void show2 ( Dictionary<string, object> state )
{
TextWriter tw2 = new StreamWriter(savepath2);
foreach (KeyValuePair<string, object> group1 in state)
{
Dictionary<string, object> group2 = (Dictionary<string, object>)group1.Value;
foreach (KeyValuePair<string, object> innerKey in group2)
{
tw2.WriteLine("Id: {0} -- Type: {1} -- Value: {2}",group1.Key, innerKey.Key, innerKey.Value);
tw2.Close();
}
}
}
Or is there any way to write the nested Dictionary
as object as input file in a txt file with stream path similar to serialize method? I don’t want to serialize it because i want to be able to check txt content:
void SaveFile ( object state )
{
using (var stream = File.Open(savepath, FileMode.Create))
{
var formatter = new BinaryFormatter();
formatter.Serialize(stream, state);
}
}