[Mono-list] calling non-static method from ctor

Lawrence Pit loz@cable.a2000.nl
Tue, 16 Apr 2002 10:08:31 +0300


Hi,

I've got a simple test program that compiles using mcs, but doesn't compile
using csc. Par. 17.10.1 of the C# spec says that this program should indeed
give a compile-time error.

PS. The funny thing is that the output from mcs runs fine in the MS runtime
:)

See output and program below:


$ csc Test.cs
Microsoft (R) Visual C# .NET Compiler version 7.00.9466
for Microsoft (R) .NET Framework version 1.0.3705
Copyright (C) Microsoft Corporation 2001. All rights reserved.

Test.cs(10,25): error CS0120: An object reference is required for the
nonstatic
        field, method, or property 'Test.Add8(int)'


$ mcs Test.cs

$ _

------------------------------------------

using System;
using System.Threading;
using System.Reflection;
using System.Reflection.Emit;

public class Test {

        public Test () : this (Add8(4), 6) {
                string hostName = System.Net.Dns.GetHostName ();
                Console.WriteLine ("Hostname: " + hostName);
        }

        public Test (int i, int j) {
                Console.WriteLine ("GOT : " + i + " : " + j);
        }


        public static void Main (String[] args) {
                Test t = new Test ();
        }

        private int Add8 (int i) {
                return i + 8;
        }

}

------------------------------------------


Greets,
Laurens Pit