some_name is a property, because when you have an instance of z_class, you do not use a method-call (which has parentheses) but just the property name:
z_class z = new z_class()
int[,,] thePropertyOfZ = z.some_name; // No parentheses
the access modifierprotected means that only the instance itself, or classes that inherit from z_class can use the setter. If the modifier is set to private only the the instance itself can access it.
z_class z = new z_class()
int[,,] toSet = new int[1,1,1];
z.some_name = toSet; // does not compile, setter is not publicly accesible
That is just the syntax on how to write a property, that is in the C# language specification. Curly braces are typically used to denote a context change, and it is the same for a function/method.
int[,,] some_name { get; protected set; }. With the class as you had you canât do what @menno had on the last line of the accepted solution. There are two ways that specific setter can be used:
class a_class : z_class {
void SomeFunc(int[,,] arr) {
some_name = arr; // can access since we derive from z_class
}
int[,,] some_prop {
get { return some_name; }
set { some_name = value; } // ditto, can access, we derive
}
}
// now can instantiate a_class, and use either some_prop or SomeFunc
// to set some_name
// we can _get_ some_name from outside the protected scope, but
// not set
z_instance = new z_class();
z_instane.some_name = new int[2,2,2]; // error, protected setter
a_instance = new a_class();
a_instance.some_prop = new int[2,2,2]; // ok, because setter is public
var arr = a_instance.some_name; // ok, because getter is public
a_instance.some_name = new int[2,2,2] // error, some_name setter still protected
Oh, yes. He actually mentiones it wonât work in a comment inside his previous reply.
I still do not understand how can I make a protected setter with python. I seem to be able to access both the property and the setter method from the instance.
Just as a clarification. A property in C# is kind of a mix of a class variable (field) and a method. It syntax sugar for getVariableX() and setVariableX(). You can do the same by implementing these two functions and a field variable. Using underscores you can simulate private/internal/protected access. Bytheway, you can also access private fields in C# by using reflection, so it shouldnât be seen as a security feature, but rather as a donât-do-this-dave hint.
I donât know if the concept of properties are very pythonic, because I see no benefit over writing two simple set and get functions directly, at least if you need to declare properties like this.
You may get a better understanding of all this when learning C#. What it looks like to me is, that very often you collide with C# concepts, which perfectly make sense in C# but are quite irrational in Python. This is also my problem with IronPython, because even for me, as being quite experienced with dotnet C# and CPython, I just get frustrated by mixing concepts in IronPython. It simply doesnât work very well for both paradigms.
I think you really have a more simple life when using C#, being able to debug with visual studio. This also makes all your printing irrelevant, since a good debugger just tells you whats going on in every single line of code.( Rhino Python debugging is not bad either, just not as powerful)
I believe, and maybe Iâm wrong but anyways I try, by translating C# to Python I learn to understand C# better. Thus, learn to create C# code. The problem is there are still a lot of things I donât know about Python (and programming in general). Trying to âhit two rabbits with a single bulletâ (literal translation of a Bulgarian saying). I want to learn both C#, get better at Python and grok General Programming at the same time.