[Mono-list] why: Quick Array Question

Ryan Janzen RyanJ at quadrus.com
Fri Nov 30 12:07:44 EST 2007

Hello list,

I have a quick question about arrays.  I am trying to compile the
following code:

using System;

namespace FooBar {
  class Program {
    static void Main(string[] args) {
      //new Object[] { foo() };  // If I uncomment this line, why does
it not compile?
      bar(new Object[] { });
      bar(new Object[] { foo() });
    public static object foo() {
      Console.WriteLine("foo"); // A side effect
      return new Object();
    public static void bar(Object o) {

If uncomment the commented line above, I get the compiler error:

"Only assignment, call, increment, decrement, and new object expressions
can be used as a statement"

To me, "new Object[] { foo() };" looks like a "new object expression".

Why is it not?

I understand that this is not typical use of the language.
I understand that there are other ways to achieve similar side effects.

I am just curious.


More information about the Mono-list mailing list