|
Hello. As far as I know, in C# all fields are private for default, if not marked otherwise.
class Foo { private string bar; } class Foo { string bar; }
I guess these two declarations are equal.
So my question is: what for should I mark private variables...
Started by abatishchev on
, 11 posts
by 11 people.
Answer Snippets (Read the full thread at stackoverflow):
Yes they are equal but I like to mark private variables as private....
I mark them as private just, I always explicitly mark private members as private.
Do what's best for readability or makes sense in your case .
Up to you.
|
|
Hi,
What is the difference between using Private Properties instead of Private Fields
private String MyValue { get; set; } // instead of private String _myValue; public void DoSomething() { MyValue = "Test"; // Instead of _myValue = "Test"; }
Is there...
Started by Yoann. B on
, 7 posts
by 7 people.
Answer Snippets (Read the full thread at stackoverflow):
And if your property is simply it will most likely be inlined by... .
The provision for a property to be private is provided only for the sake of completeness.
You would seldom want to make a property private.
To be protected, for instance.
|
|
Is there a notion of object-private in any OOP language ?? I mean more restrictive than the classic private access ?
Private (or class-private) restricts the access to the class itself. Only methods that are part of the same class can access private members...
Started by wj on
, 8 posts
by 8 people.
Answer Snippets (Read the full thread at stackoverflow):
There is no way to ....
In Java, which is what it looks like you are writing, "private" means class-private.
I don't think this kind of distinction of class vs object private exists for the most common that actually has this feature.
|
Ask your Facebook Friends
|
What about a feature in an upcoming Delphi version enabling that?
Maybe it could be a compiler switch promoting all private s to strict private s.
... or it could be a feature of the new non-legacy compiler font-end Nick Hodges was talking about. =>...
Started by ulrichb on
, 5 posts
by 5 people.
Answer Snippets (Read the full thread at stackoverflow):
Strict private: Methods in the....
private: Methods in the class and anything in the same unit can access.
I interpret that as, if codegear is going to change the behaviour of private subclasses can access.
That it all works for you.
|
|
I'm trying to figure out what is the smartest way to name private methods and private static methods in C#.
Background: I know that the best practice for private members is underscore-prefix + camelcase. You could argue this with me, but trust me I've...
Started by Mark Rogers on
, 6 posts
by 6 people.
Answer Snippets (Read the full thread at stackoverflow):
Should be PascalCase
public void DoWork() {} private void StillDoWork() {} private static void ContinueToDoWork() {}
I don't know about industry standards but use Pascal casing even for private development don't distinguish between....
|
|
Is there a difference between having a private const variable or a private static readonly variable in C# (other than having to assign the const a compile-time expression)?
Since they are both private, there is no linking with other libraries. So would...
Started by Hosam Aly on
, 9 posts
by 9 people.
Answer Snippets (Read the full thread at stackoverflow):
For....
private static readonly int[] values = new int[] { 1, 2, 3 };
So if you need an array constant readonly is the only way to go.
private const int[] values = new int[] { 1, 2, 3 };
But you can create it using a static readonly field.
|
|
As an example:
public class Foo { private Foo() {} } public class Bar extends Foo { private Bar() {} static public doSomething() { } }
That's a compilation error right there. A class needs to, at least, implicitly call its superclass's default constructor...
Started by Hans Sjunnesson on
, 5 posts
by 5 people.
Answer Snippets (Read the full thread at stackoverflow):
The only way you would be able from Bar while it's a subclass of Foo, ... .
You need to make Foo's constructor package private at the very least (Though I'd to create an instance of Bar for as long as Foo has a private constructor.
You can't.
|
|
Python gives us the ability to create 'private' methods and variables within a class by prepending double underscores to the name, like so: *__myPrivateMethod()*. How, then, can one explain this
>>> class MyClass: ... def myPublicMethod(self)...
Started by wbowers on
, 9 posts
by 9 people.
Answer Snippets (Read the full thread at stackoverflow):
Private....
From http://www.faqs.org/docs/diveintopython/fileinfo_private.html
Strictly speaking, private private; internally, the names of private methods and attributes are mangled and unmangled on the fly, ever do it in real code.
|
|
I have the following code. Is it not the exact code which I am using since it is internal to my place of work, but is a representation of the scenario which I am encountering.
public class Service : ServiceBase { private static readonly Service _instance...
Started by Nippysaurus on
, 4 posts
by 4 people.
Answer Snippets (Read the full thread at stackoverflow):
}
The static initializers? That would be more robust:
private....
Public class Service : ServiceBase { // Initialize a first private static readonly string a = @"D:\test.txt"; private static readonly Service _instance = new Service(); ...
|
|
If I have a private variable that I want to have some internal validation on, and I want to keep that validation in one place, I put it behind a getter/setter and only access it thorugh that getter/setter. That's useful when dealing with public properties...
Answer Snippets (Read the full thread at stackoverflow):
} private class Eye { private int = 0; } else { _eyeOrientation = value % 360; } } } }
Just put your private attribute and public getters/setters into a ....
But the NeedsEye class has not // any access to members of the Eye class .
|