当在类内部引用值时(来自同一类),应该使用可以从其他类中访问的字段还是属性?
例如,在我的类中,我应该使用哪种方式引用变量,为什么?
public static class Debug
{
private static int _NumberOfEvents = 1;
public static int NumberOfEvents
{
get
{
return _NumberOfEvents;
}
set
{
_NumberOfEvents = value;
}
}
public static void LogEvent(string Event)
{
//This way?
Console.WriteLine("Event {0}: " + Event, _NumberOfEvents);
_NumberOfEvents++;
//Or this way?
Console.WriteLine("Event {0}: " + Event, NumberOfEvents);
NumberOfEvents++;
}
}
感谢