I have the following class:
class ProvisionCollec tion
{
...
private int m_VarianceCount ;
public int VarianceCount
{
get { return m_VarianceCount ; }
}
public static ProvisionCollec tion GetProvisions(. ..)
{
ProvisionCollec tion list = new ProvisionCollec tion();
... populate collection ...
m_VarianceCount = (int)cmd.Parame ters["@SP_66_COU NT"].Value;
return list;
}
}
My question: Should this static method have access to modify the
private instance variable "m_VarianceCoun t"? Because right now it
works perfectly, but it doesn't seem like it should.
Thanks,
Jordan
May 10 '07
14 9923
On May 11, 4:57 pm, Jordan Marr <jnm...@hotmail .comwrote:
I don't see what the problem is. Static doesn't mean you can't access
instance methods. You can as long as you have an instance to operate
on, which your code shows you do.- Hide quoted text -
But I accessed a *private* member of the instance from a static (non
instanced) method. It just doesn't seem like that should work!!
No, that's fine. From within a type, you can access private members of
any instance of the same type.
Jon
On May 11, 11:55 am, "Jon Skeet [C# MVP]" <s...@pobox.com wrote:
On May 11, 4:36 pm, Jordan Marr <jnm...@hotmail .comwrote:
Could you post a short but complete program we can compile showing the
above working?
Create a new console app and paste the following two .cs modules:
<snip>
That doesn't show any bugs. Note that you're accessing the member
variables via a reference to an instance, which is fine - and is *not*
what your first post was showing.
Jon
I see what you are saying now. I did indeed misrepresent the
problem. My code that compiled is calling the private member from an
actual instance.
I didn't realize that was valid to reference a private member
"externally " like that (even though the static member is declared
internally). It is convenient that I am able to do this though!
Does "shared" work the same way in VB?
Jordan
Jordan Marr <jn****@hotmail .comwrote:
<snip>
I see what you are saying now. I did indeed misrepresent the
problem. My code that compiled is calling the private member from an
actual instance.
I didn't realize that was valid to reference a private member
"externally " like that (even though the static member is declared
internally). It is convenient that I am able to do this though!
Does "shared" work the same way in VB?
Yes, but it's really irrelevant to whether the method is static or not.
It would be the same situation if you try to access private members of
one instance from another. Effectively, the fact that it's a static
method is irrelevant except that there's no "this" to refer to.
--
Jon Skeet - <sk***@pobox.co m> http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too
"Jordan Marr" <jn****@hotmail .comschrieb im Newsbeitrag
news:11******** *************@e 65g2000hsc.goog legroups.com...
>
But I accessed a *private* member of the instance from a static (non
instanced) method. It just doesn't seem like that should work!!
You seem to suppose private restricts the access to member to methods of the
same *instance*.
But it only limits acces to the same *class* not to the same *instance*.
Christof
On May 14, 3:05 am, "Christof Nordiek" <c...@nospam.de wrote:
"Jordan Marr" <jnm...@hotmail .comschrieb im Newsbeitragnews :11************ *********@e65g2 000hsc.googlegr oups.com...
But I accessed a *private* member of the instance from a static (non
instanced) method. It just doesn't seem like that should work!!
You seem to suppose private restricts the access to member to methods of the
same *instance*.
But it only limits acces to the same *class* not to the same *instance*.
Christof
You're right, that is exactly what I was supposing. But I got it
now.
Thanks!
Jordan This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: James |
last post by:
Hello Java NG,
I not sure if this is the right NG for this type of question but if not
please let me know which is, TIA
Any way first off let me say I'm a student and this WAS last weeks lab,
turned in, graded and passed so I'm not trying to get someone to do my lab
assignments, but after I got this back I was reading about the DecimalFormat
and I tried to format my output but I keep getting an error message. can
anyone please tell me...
|
by: Tim Clacy |
last post by:
Would some kind soul suggest a pre-processor test for the C++ language
revision whereby class static variables were specified to refer to the same
instance? Specifically, the following Singleton template will work with some
compilers but not with older ones (because every module that includes the
header gets its own unique static 'instance'):
template<typename T>
struct Singleton
{
static T& Instance() { static T instance; return...
|
by: Mark Shelor |
last post by:
I've encountered a troublesome inconsistency in the C-language Perl
extension I've written for CPAN (Digest::SHA). The problem involves the
use of a static array within a performance-critical transform function.
When compiling under gcc on my big-endian PowerPC (Mac OS X),
declaring this array as "static" DECREASES the transform throughput by
around 5%. However, declaring it as "static" on gcc/Linux/Intel
INCREASES the throughput by...
|
by: Neil Kiser |
last post by:
I'm trying to understand what defining a class as 'static' does for
me.
Here's an example, because maybe I am thinking about this all wrong:
My app will allows the user to control the fonts that the app uses.
So I will need to change the fonts depending on what settings the user
has entered. However, it seems kind of wasteful to me to go to teh
registry, fetch the font information and create new font objects for
every form that I am...
|
by: Frank Rizzo |
last post by:
Hello,
I have a class with all static methods that is called by multiple
threads. I was wondering what effect that has on the competing threads.
Does Thread2 have to wait until Thread1 is done with the
StaticClass.Method1 before it can use it?
What if I removed static methods and made all the threads instantiate
its own copy of the class? Would that remove the waiting contention?
| |
by: |
last post by:
Hi,
How long do webservice objects live for? In particular, if i have static
variables filled with data from a static constructor in a webservice, how
long will that data persist?
thxs
|
by: Kevin Prichard |
last post by:
Hi all,
I've recently been following the object-oriented techiques discussed
here and have been testing them for use in a web application. There is
problem that I'd like to discuss with you experts.
I would like to produce Javascript classes that can be "subclassed"
with certain behaviors defined at subclass time. There are plenty of
ways to do this through prototyping and other techniques, but these
behaviors need to be static and...
|
by: RB |
last post by:
Hi clever people :-)
I've noticed a lot of people stating not to use static variables with
ASP.NET, and, as I understand it, the reason is because the variable is
shared across user sessions - which is Very Bad (tm) for reasons I
understand!
However, does this rule apply only to global static variables, or does
it apply to procedure-level static variables.
|
by: Luis Zarrabeitia |
last post by:
Quoting Joe Strout <joe@strout.net>:
I'm sure your credentials are bigger than mine. But he is right. A lot of
languages have ditched the "concept" of a static variable on a method (how do
you parse that sentence, btw?) in favour of using encapsulation. Of the top of
my head, there is Java, C# and Python, and I think even PHP and Perl. They call
them "private variables", including the
name-mangled-publicly-accessible-__python's...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
| |
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| |