调试时C#从TracePoints获取字典值

时间:2017-03-10 17:38:28

标签: c# .net visual-studio debugging dictionary

使用跟踪点时获取字典键值对的正确语法是什么?

使用以下属性

public Dictionary<string, decimal> SomeDictionary { get; set; }

我试图在setter方法上设置一个断点来跟踪所有传入的值。我尝试过以下但没有一个能够正常工作。

{value}        'this gives me a count of how many items are in the dictionary

{value.Value}  'throws an exception, 'Value' doesn't exist

{value[Value]} 'the name 'Value' does not exist in the current context

enter image description here

2 个答案:

答案 0 :(得分:1)

根据您的 public class Example { public Dictionary<string, decimal> SomeDictionary { get; set; } public Example() { SomeDictionary = new Dictionary<string, decimal>(); string key = "key"; SomeDictionary[key] = 10.0M; } } static void Main(string[] args) { var example = new Example(); Console.ReadKey(); }

SomeDictionary: {SomeDictionary}; SomeDictionary[key]: {SomeDictionary[key]}

如果在定义字典并添加密钥后将tracepoint放在构造函数的末尾 - Tracepoint操作:

SomeDictionary: Count = 1; SomeDictionary[key]: 10.0

我们可以检查字典 - 输出:

Python 2

答案 1 :(得分:0)

您可以使用

引用字典
{ map["key1"] }

或使用变量访问keyvalue对。

Dot-sourcing