如何在foreach循环中使用KeyValuepair到达结构内容?
这是我的方法,问题是Innerkey。值是struct,在txt文件中,我只有struct而不是结构内容的名称。 状态
是嵌套对象是另一个dic。
如何在TXT文件中编写结构内容?
private 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();
}
}
}
还是有什么方法可以将嵌套字典作为对象作为输入文件,其中具有类似于序列化方法的流路径的输入文件?我不想序列化,因为我希望能够检查TXT内容:
private void SaveFile(object state)
{
using (var stream = File.Open(savepath, FileMode.Create))
{
var formatter = new BinaryFormatter();
formatter.Serialize(stream, state);
}
}
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 dic that the object is another dic.
How can i write struct content in my txt file?
private 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:
private void SaveFile(object state)
{
using (var stream = File.Open(savepath, FileMode.Create))
{
var formatter = new BinaryFormatter();
formatter.Serialize(stream, state);
}
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论