开发者

Why doesn't a properies code block get hit when stepping though C# code?

I'm trying to understand how Properties work. I've found that stepping though sample code can be very helpful. But When I step through a small program with a simple class and Property, the Property never gets hit. Which makes me wonder if its even being used. With the code below I can see that the private variables of the class are touched but nothing else. I'm confused. Plus if anyone has found a site or video that was their "ah hah" moment for understanding class properties I'd love to see it.

using System;

public class Customer
{
    private int m_id = -1;

    public int ID
    {
        get
        {
            return m_id;
        }
        set
        {
            m_id = value;
        }
    }

    private string m_name = string.Empty;

    public string Name
    {
        get
        {
            return m_name;
        }
        set
        {
            m_name = value;
        }
    }
}

public class CustomerManagerWithPropertie开发者_Python百科s
{
    public static void Main()
    {
        Customer cust = new Customer();

        cust.ID = 1;
        cust.Name = "Amelio Rosales";

        Console.WriteLine(
                "ID: {0}, Name: {1}",
                cust.ID,
                cust.Name);

        Console.ReadKey();
    }
}

Thanks!


You have to modify the default debugger settings to step into properties (Tools|Options ->Debugging->General):

Why doesn't a properies code block get hit when stepping though C# code?


You should check your settings in Visual Studio, in: Tools -> Options -> Debugging, there is the option:

Step over properties and operators (Managed only)

Make sure this is unchecked.


In Visual Studio 2010, the default is to step over properties. You can change this behavior in the Tools -> Options -> General -> Step over properties and operators (Managed only).

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜