Linked Questions
12 questions linked to/from Why are private fields private to the type, not the instance?
13
votes
3
answers
2k
views
Why private members of a class instance are getting available in Equals() method body? [duplicate]
Possible Duplicate:
Why are my privates accessible?
Why are private fields private to the type, not the instance?
Most probably I am missing an obvious fact but I cannot really see the reason:
...
5
votes
6
answers
251
views
Why is calling a protected or private CSharp method / variable possible? [duplicate]
Possible Duplicate:
Why are private fields private to the type, not the instance?
Consider the following class:
public class Test
{
protected string name;
private DateTime dateTime;
...
3
votes
4
answers
311
views
Access to private members of class [duplicate]
public class Class1
{
private object field;
public Class1(Class1 class1)
{
this.field = class1.field;
}
private void Func(Class1 class1)
{
this.field = class1....
0
votes
1
answer
174
views
Why is accessing a private function of another object instance valid? [duplicate]
Possible Duplicate:
Why are private fields private to the type, not the instance?
Consider the following code:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;...
21
votes
5
answers
1k
views
Why is this private member accessible?
I have this class:
class C
{
private String msg;
public void F(C obj, String arg)
{
obj.msg = arg; // this is strange, the msg shouldn't be accessible here.
}
public ...
28
votes
3
answers
8k
views
Why and how does C# allow accessing private variables outside the class itself when it's within the same containing class?
I don't know if the question is descriptive enough but why and how does this behaviour exist?:
public class Layer
{
public string Name { get; set; }
private IEnumerable<Layer> children;...
28
votes
2
answers
3k
views
Why can private member variable be changed by class instance?
class TestClass
{
private string _privateString = "hello";
void ChangeData()
{
TestClass otherTestClass = new TestClass();
otherTestClass._privateString = "world";
}
}
...
7
votes
4
answers
2k
views
In .NET, Why Can I Access Private Members of a Class Instance within the Class?
While cleaning some code today written by someone else, I changed the access modifier from Public to Private on a class variable/member/field. I expected a long list of compiler errors that I use to "...
4
votes
5
answers
415
views
Why are my privates accessible?
I have the following code:
public class PersonInitializer
{
private Person _person;
public static Person LoadFromFile(string path)
{
PersonInitializer x = new PersonInitializer();...
9
votes
2
answers
1k
views
C# protected field access [duplicate]
(This question is a follow-up to C# accessing protected member in derived class)
I have the following code snippet:
public class Fox
{
protected string FurColor;
private string furType;
...
1
vote
2
answers
127
views
How are private members of a class accessed via member functions of the class on memory level?
class TestMemberOuter1{
private int data=30;
class Inner{
void msg(){System.out.println("data is "+data);}
}
void display(){
Inner in=new Inner();
in.msg();
}
public static void main(...
2
votes
3
answers
130
views
Trouble with Protected and Private access modifier
guys,thanks for your time.
As we known,the key words 'Private' and 'Protected' are very useful to keep some methods,fields,properties from invalid accessing outside the class.But I had got a problem ...