Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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 CustomerManagerWithProperties
{
    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!

like image 426
JimDel Avatar asked Dec 29 '25 06:12

JimDel


1 Answers

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

enter image description here

like image 149
BrokenGlass Avatar answered Dec 30 '25 18:12

BrokenGlass