Author | Message | Time |
---|---|---|
Fr0z3N | 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. | July 12, 2004, 5:06 PM |
Eibro | [quote author=Rubicon link=board=5;threadid=7678;start=0#msg69979 date=1089651993] 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]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. | July 12, 2004, 6:31 PM |
Yoni | Surely you can see the statement being valid. Just overload operator+ to return a reference... | July 12, 2004, 9:58 PM |
Myndfyr | [quote author=Yoni link=board=5;threadid=7678;start=0#msg70029 date=1089669493] Surely you can see the statement being valid. Just overload operator+ to return a reference... [/quote] 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. | July 12, 2004, 11:00 PM |
K | [quote author=Myndfyre link=board=5;threadid=7678;start=0#msg70051 date=1089673256] [quote author=Yoni link=board=5;threadid=7678;start=0#msg70029 date=1089669493] Surely you can see the statement being valid. Just overload operator+ to return a reference... [/quote] 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] Yoni is talking about Eibro's comment that the original code: [code] (Variable + 6) = Array[5]; [/code] 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 [code] *(Variable + 6) = Array[5]; [/code] 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. | July 12, 2004, 11:07 PM |
Eibro | Yes, I thought of that too, but returning a reference from opertor+() doesn't make sense either. | July 12, 2004, 11:41 PM |