how can reach struct content with KeyValuePair in foreach loop?

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);
    }
}

You should override ToString() method inside your innerKey.Value struct. That way you will define exactly which data you want to be saved. Otherwise you will be given only the name of your struct - as is the case now. Look at the example below to see what I mean:

public struct Person
{
	public string name;
	public int age;
	public float weight;
	
	public Person(string name, int age, float weight)
	{
		this.name = name;
		this.age = age;
		this.weight = weight;
	}
	
	// Override this method, and define which data you want to be saved to the file. If you don't override ToString() method, only your struct name will be saved - which is not what you want.
	public override string ToString()
	{
		string s = name + ";" + age + ";" + weight + ";";
		return s;
	}
}