Hi,

Given the following program, I have a question about Mono and .Net.  This is
not a bug in Mono because I think the same thing happens on Windows, but I
was hoping someone could explain it to me.  The line below with the comment
is surprising because it is accessing a private variable of another
instance.  Why does it compile?  Shouldn't it say that member bar is not
visible?

Thanks,

Vlad



using System;

namespace Test
{
        public class Foo
        {
                private string bar = null;
                
                public Foo(string bar)
                {
                        this.bar = bar;
                }
                private Foo(Foo foo)
                {
                        this.bar = foo.bar; //This line is surprising
                }
                
                public Foo Copy()
                {
                        return new Foo(this);
                }
        }
        class MainClass
        {
                public static void Main(string[] args)
                {
                        Foo foo = new Foo("foobar");
                        Foo foobar = foo.Copy();
                }
        }
}


Attachment: smime.p7s
Description: S/MIME cryptographic signature

_______________________________________________
Mono-devel-list mailing list
Mono-devel-list@lists.ximian.com
http://lists.ximian.com/mailman/listinfo/mono-devel-list

Reply via email to