[Mono-dev] private members

2007-12-10 Thread Vladimir Giszpenc
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();
}
}
}




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


Re: [Mono-dev] private members

2007-12-10 Thread Mark Probst
 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?

The scope of access protection is the class, not the instance.

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