[Mono-list] Class Property Initializer Question...

Ryan Kirkpatrick ryan.kirkpatrick at inovonics.com
Mon Jul 20 21:27:22 EDT 2009

When I compile and run the following code with Visual Studio, the output 
  is 'Blue/Green' and 'Red/Red'. When I compile and run the same code 
with Mono (2.4.2.x), the output is 'Blue/Green' and 'Blue/Green'. For 
some reason the initial values I am setting as part 'new' line are not 
being overwritten or worse just ignored. This does appear to be a 
compiler issue, since if I run the EXE generated by VS with Mono then I 
get 'Blue/Green' and 'Red/Red'. With gmcs I am simply compiling with 
'gmcs program.cs'. Is there something I am missing? Or did I find a bug? 


using System;
using System.Collections.Generic;

namespace ConsoleApplication2 {
     enum Colors { Red = 0, Green = 1, Blue = 2 };
     class Screen {
         public Colors fore = Colors.Blue;
         public Colors back;
         public Screen() { back = Colors.Green; }

     class Program {
         static void Main(string[] args) {
             Screen a = new Screen();
             Console.WriteLine("{0} / {1}", a.fore, a.back);
             a = new Screen() { back = Colors.Red, fore = Colors.Red };
             Console.WriteLine("{0} / {1}", a.fore, a.back);


Ryan Kirkpatrick <ryan.kirkpatrick at inovonics.com>, 303-209-7190
Senior Design Engineer
Inovonics Wireless Corporation

This email transmission and any documents, files or previous email
messages attached to it contains information that is confidential
or legally privileged. If you are not the intended recipient or a
person responsible for delivering this transmission to the intended
recipient, you are hereby notified that you must not read this
transmission and that any disclosure, copying, printing,
distribution or use of this transmission is strictly prohibited. If
you have received this transmission in error, please immediately
notify the sender by telephone or return email and delete the
original transmission and its attachments without reading or saving
in any manner. Thank you.

More information about the Mono-list mailing list