gpt4 book ai didi

visual-studio-2010 - VS2010在调试时将数组/集合数据保存到文件中

转载 作者:行者123 更新时间:2023-12-03 13:21:46 24 4
gpt4 key购买 nike

在VS2010中进行调试时,有什么方法可以将数组/列表/集合数据保存到文件中?

例如,在此代码中:

var addressGraphs = from a in context.Addresses
where a.CountryRegion == "Canada"
select new { a, a.Contact };

foreach(var ag in addressGraphs) {
Console.WriteLine("LastName: {0}, Addresses: {1}", ag.Contact.LastName.Trim(),
ag.Contact.Addresses.Count());



foreach(var Address in ag.Contact.Addresses) {
Console.WriteLine("...{0} {1}", Address.Street1, Address.City);
}
}


我想在第一行“ foreach”行上设置一个断点,然后将“ addressGraph”中的数据保存到文件中。

其中“ a”包含以下字段:

   int addressID
string Street1
string City
<Ect.>


“联系人”包含以下字段:

   string FirstName
string LastName
int contactID
<Ect.>


我希望文件包含集合中每个项目的每个字段的值。

我看不到这样做的明显方法。可能吗?

最佳答案

遇到断点时,打开Immediate窗口,然后使用Tools.LogCommandWindowOutput将输出转储到文件中:

>Tools.LogCommandWindowOutput c:\temp\temp.log
?addressGraphs
>Tools.LogCommandWindowOutput /off


注意:您可以使用 Log,这是 Tools.LogCommandWindowOutput的别名



更新:
>字符很重要。另外, log别名区分大小写。
看截图:

关于visual-studio-2010 - VS2010在调试时将数组/集合数据保存到文件中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7194691/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com