it's like:
(Variable + 6) = Array[5];
how the hell would that convert to C#? It's like backwards C++.
Variable = (Array[5] + 6); would make more sence.
Quote from: Rubicon on July 12, 2004, 12:06 PM
it's like:
(Variable + 6) = Array[5];
how the hell would that convert to C#? It's like backwards C++.
Variable = (Array[5] + 6); would make more sence.
No, those two aren't equivalent. The only way I see the first being a valid statement is if it were
*(Variable + 6) = Array[5];, since (Variable + 6) isn't an l-value and thus cannot be assigned to.
Surely you can see the statement being valid. Just overload operator+ to return a reference...
Quote from: Yoni on July 12, 2004, 04:58 PM
Surely you can see the statement being valid. Just overload operator+ to return a reference...
First, you can't overload operators like that in C#....
Second, Eibro was correct in saying that *(Variable + 6) would be correct syntax. You'd need to put that within an
unsafe code block and also compile with the /unsafe switch.
Quote from: Myndfyre on July 12, 2004, 06:00 PM
Quote from: Yoni on July 12, 2004, 04:58 PM
Surely you can see the statement being valid. Just overload operator+ to return a reference...
First, you can't overload operators like that in C#....
Second, Eibro was correct in saying that *(Variable + 6) would be correct syntax. You'd need to put that within an unsafe code block and also compile with the /unsafe switch.
Yoni is talking about Eibro's comment that the original code:
(Variable + 6) = Array[5];
could not compile in C++ since (Variable + 6) would not be an L-Value. He is correct in saying that since we are not given a type for Variable, its possible that the +operator is overloaded and (Variable+6) is returning a reference, and hence a valid L-value.
To convert the code
*(Variable + 6) = Array[5];
to C# probably wouldn't require using unsafe code if we were given more information, such as the type of Variable. It would simply require changing the pointer arithmatic to an array index.
Yes, I thought of that too, but returning a reference from opertor+() doesn't make sense either.