我收到以下编译错误:cannot modify the return value of 'Dictionary<string, SessionLogDates>.this[string]' because it is not a variable
。
public static Dictionary<string, SessionLogDates> RegisteredTimes = new Dictionary<string, SessionLogDates>();
添加的键值对如下所示:
var tempDate = DateTime.Now;
RegisteredTimes.Add(requestUI, new SessionLogDates
{
RequestStart = tempDate,
LastProcess = tempDate
});
struct
声明如下:
public struct SessionLogDates
{
public DateTime RequestStart { get; set; }
public DateTime LastProcess
{
get { return _lastProcess; }
set
{
_lastProcess_cache = _lastProcess;
_lastProcess = value;
}
}
public bool LogCurrentProcess
{
get
{
var tempValue = _lastProcess_cache != _lastTimeLog;
if (tempValue)
_lastTimeLog = _lastProcess_cache;
return tempValue;
}
}
public bool InitialLog
{
get { return LastProcess == RequestStart; }
}
private DateTime _lastProcess { get; set; }
private DateTime _lastProcess_cache { get; set; }
private DateTime? _lastTimeLog { get; set; }
}
如何以这种方式重新分配?
RegisteredTimes[requestUI].LastProcess = DateTime.Now;
我是否需要更改为class
而不是struct
?
详细原因将不胜感激。