当引用类内的值时(来自同一类内),您应该使用可以从其他类访问的字段还是属性?
例如,我应该以哪种方式引用班级中的变量,为什么?
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++;
}
}
谢谢