Copy object values in Visual Studio debug mode

前端 未结 12 517
轻奢々
轻奢々 2021-01-29 19:17

In Visual Studio debug mode it\'s possible to hover over variables to show their value and then right-click to \"Copy\", \"Copy Expression\" or \"Copy Value\".

In case t

12条回答
  •  挽巷
    挽巷 (楼主)
    2021-01-29 19:40

    By using attributes to decorate your classes and methods you can have a specific value from your object display during debugging with the DebuggerDisplay attribute e.g.

    [DebuggerDisplay("Person - {Name} is {Age} years old")]
    public class Person
    {
      public string Name { get; set; }
      public int Age { get; set; }
    }
    

提交回复
热议问题