[Mono-list] property access vs. variable

Ian McCullough Ian McCullough" <ipmcc@pobox.com
Mon, 8 Apr 2002 11:26:33 -0400


Hello all,

I am new to the list, but have been playing with .NET on windows for a
while, and have been following the development of mono.  I have been trying
to port some of the "non-GUI" stuff that I've written for VS.NET to mono and
I've run into some a problem that doesn't seem to stem from an unimplemented
class.  The following code compiles fine on VS.NET, looks perfectly
reasonable to me, and yet throws an error with mcs.

    string command = "EXEC";
    for (int i = 0; i <= theEvent.Args.GetUpperBound(0); i++)
     command = command + ((theEvent.Args[i].Length > 0) ? " " +
theEvent.Args[i] : "");

with theEvent.Args being a string[].  mcs gives the following error:

./upload.cs(1439) error CS118: Expression denotes a `property access' where
a `variable' was expected
/usr/bin/mcs: line 2: 11747 Segmentation fault      /usr/bin/mono
/usr/bin/mcs.exe $*

If I change that code to:

    string command = "EXEC";
    foreach (string item in theEvent.Args)
        command = command + ((item.Length > 0) ? " " + item : "");

Everything compiles just fine. (or rather continues on to the next instance
of the syntax above, which I used quite frequently)  Now coding style aside
(yes I do realize that the second version is definitely cleaner and probably
faster, and that this task is probably better suited to a StringBuilder
class) I don't see what's wrong with the first one.  The obvious conclusion
to draw from the error is that there is some restriction in where you can
use a property vs. where you can use a variable. I have never run across
this before.

Not to jump the gun, but I assume because VS.NET compiles the original code,
that it is valid C# code.  I checked the TODO in the mcs source tree and
browsed through the last two months of mono-list archives looking for
previous addressings of this problem and didn't find anything.  I also
checked my trusty O'Reilly C# book which seemed to contain no mention of
restrictions on where you can use properties vs. variable.  What's the deal
here?  Can anyone shed any light on this?


Ian