A
Alistair Welchman
I have a Hashtable of ints keyed on Guids, and I want to do the following:
foreach ( DataRow row in dsWorkDays.Tables[0].Rows )
{
Guid PersonId = (Guid)row["PersonID"];
DateTime Day = (DateTime)row["Datum"];
rLastWorkDays.Increment( PersonId, Day.DayOfWeek,
++((int)Offsets[PersonId]) );
}
that is, increment the offset for the current Guid and call a function with
the new value.
This fails at compile time with the message
The left-hand side of an assignment must be a variable, property or
indexer
I assume that the rule is that when you access a hashed value type, you
don't get a reference but a copy. When you assign the copy, everything is
OK, but when, like here, you just try and perform an operation on it, the
compiler recognises that the operation will always be useless because it's
performed on a temporary and refuses to comply.
If this is right, my question is: why isn't boxing automatically invoked? I
can do it myself of course, but then I have to write about the same amount
of code as I would just to store the value, increment it, call the function,
and tuck the incremented value back in the Hashtable. Any clarifications?
Perhaps I've misunderstood the rule.
Alistair Welchman
foreach ( DataRow row in dsWorkDays.Tables[0].Rows )
{
Guid PersonId = (Guid)row["PersonID"];
DateTime Day = (DateTime)row["Datum"];
rLastWorkDays.Increment( PersonId, Day.DayOfWeek,
++((int)Offsets[PersonId]) );
}
that is, increment the offset for the current Guid and call a function with
the new value.
This fails at compile time with the message
The left-hand side of an assignment must be a variable, property or
indexer
I assume that the rule is that when you access a hashed value type, you
don't get a reference but a copy. When you assign the copy, everything is
OK, but when, like here, you just try and perform an operation on it, the
compiler recognises that the operation will always be useless because it's
performed on a temporary and refuses to comply.
If this is right, my question is: why isn't boxing automatically invoked? I
can do it myself of course, but then I have to write about the same amount
of code as I would just to store the value, increment it, call the function,
and tuck the incremented value back in the Hashtable. Any clarifications?
Perhaps I've misunderstood the rule.
Alistair Welchman