I have been reading sime material in .NET that throws some doubt on my
understanding of shared procedures.
With regard to object programming I assumed that variables declared
within a class were private to the class, each object would have
access to it's ver own copy of that variable. With regard to the
methods defined for a class, I assumed that these are shared among all
objects of the class, the code acting on the instances own copy of the
variables.
Now shared variables are attached to the class and not an instance of
the class and it makes sense that the methods that act on these should
be declared as shared, but only if I want to call them without having
an instance of the class. Can non-shared methods also be used on
shared variables?
John L 8 1255
"gemel" <jo***@glenavon1.demon.co.uk> wrote in message
news:4b********************************@4ax.com... I have been reading sime material in .NET that throws some doubt on my understanding of shared procedures.
With regard to object programming I assumed that variables declared within a class were private to the class, each object would have access to it's ver own copy of that variable. With regard to the methods defined for a class, I assumed that these are shared among all objects of the class, the code acting on the instances own copy of the variables.
Now shared variables are attached to the class and not an instance of the class and it makes sense that the methods that act on these should be declared as shared, but only if I want to call them without having an instance of the class. Can non-shared methods also be used on shared variables?
No. It'll throw up a compile time error. The only variables allowed in
shared methods are shared variables, variables local to the method and
parameters passed into the method.
Imran.
> I have been reading sime material in .NET that throws some doubt on my understanding of shared procedures.
With regard to object programming I assumed that variables declared within a class were private to the class, each object would have access to it's ver own copy of that variable.
You don't mean 'private', I think what you mean is called 'instance' members
as opposed to 'static' (Shared in VB.NET) members.
Whether a variable is Private or Public determines whether it can be seen by
code outside the class.
Whether a member variable is Shared or Instance determines whether there is
one for all instances of the class (for the whole program) or whether there
is a fresh one for every instance of the class.
Member functions can also be Shared or Instance, a Shared function can be
called without the need to have an instance of the class, but it thus can't
access variables (or other member functions) that are instance members.
With regard to the methods defined for a class, I assumed that these are shared among all objects of the class, the code acting on the instances own copy of the variables.
Now shared variables are attached to the class and not an instance of the class and it makes sense that the methods that act on these should be declared as shared, but only if I want to call them without having an instance of the class. Can non-shared methods also be used on shared variables?
John L
> Can non-shared methods also be used on shared variables?
Yes, they can.
But obviously not the other way round - a shared method can't change a
non-shared variable, because it wouldn't know which instance of the class
(that's if any were even in existence) to modify the data of. John L
Thanks for your prompt reply. Yes I did mean instance variable. But my
assumptions about code are correct aren't they? That is, methods of a
class whether shared or instance, exist only once, whereas the
instance variable belongs to each instance.
John L
On Tue, 12 Oct 2004 05:23:01 -0700, "Bonj"
<Bo**@discussions.microsoft.com> wrote: Can non-shared methods also be used on shared variables?
Yes, they can. But obviously not the other way round - a shared method can't change a non-shared variable, because it wouldn't know which instance of the class (that's if any were even in existence) to modify the data of.
John L
Oops..I answered the wrong question :) I think Bonj already answered this
for you.
Imran. No. It'll throw up a compile time error. The only variables allowed in shared methods are shared variables, variables local to the method and parameters passed into the method.
Imran.
"gemel" <jo***@glenavon1.demon.co.uk> wrote in message
news:c3********************************@4ax.com... Thanks for your prompt reply. Yes I did mean instance variable. But my assumptions about code are correct aren't they? That is, methods of a class whether shared or instance, exist only once, whereas the instance variable belongs to each instance.
That is correct. Method code is never copied - whether they are shared or
instance methods. And yes - instance variables belong to each individual
instance of the class.
Imran.
"gemel" <jo***@glenavon1.demon.co.uk> schrieb: With regard to object programming I assumed that variables declared within a class were private to the class, each object would have access to it's ver own copy of that variable.
That's only partially true. A class (in other words, one of its instances)
can have access to private variables declared in the class even if they
belong to another instance of the class.
--
Herfried K. Wagner [MVP]
<URL:http://dotnet.mvps.org/>
How would they know which instance of the class to use unless they are
qualified by something like a global variable set a specific class instance?
"Herfried K. Wagner [MVP]" wrote: "gemel" <jo***@glenavon1.demon.co.uk> schrieb: With regard to object programming I assumed that variables declared within a class were private to the class, each object would have access to it's ver own copy of that variable.
That's only partially true. A class (in other words, one of its instances) can have access to private variables declared in the class even if they belong to another instance of the class.
-- Herfried K. Wagner [MVP] <URL:http://dotnet.mvps.org/>
This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: Dragonhunter |
last post by:
Hello,
The aspfaq.com seems to really push stored procedures, and I hear the
same advice here all the time. So I want to take the advice.
Is it possible to create and practically maintain,...
|
by: Robert Scheer |
last post by:
Hi.
I wrote some stored procedures used by a web application. As I am
fairly new to Oracle, I am missing some concepts when creating these
procedures, as a result, the application is suffering...
|
by: inline_four |
last post by:
We've been running a database on a shared server. The traffic on our
site has been picking up steadily and it seems as though we're running
into sporadic downtime on the database. Sometimes when...
|
by: Mike J |
last post by:
I have several stored procedures that run fine from my SQL Server
database (via the exec command.), though when I call these procedures
from my web application, they do not complete. I have other...
|
by: BlueDragon |
last post by:
The place where I work is moving to MS SQL Server from Lotus Notes. I
have done a lot of coding in Lotus Notes, and have, I suppose,
intermediate skills in basic SQL -- queries, insert, updates,...
|
by: Daniel Fernandes |
last post by:
Hi there
Is there any difference I need to be aware when I create a class with
only shared members & procedures when compared to a module (which is a
shared class) ?
I am asking this because...
|
by: John |
last post by:
Hi
When developing vb.bet winform apps bound to sql server datasource, is it
preferable to use SELECTs or stored procedure to read and write data from/to
SQL Server? Why?
Thanks
Regards
|
by: DeanL |
last post by:
Hi all,
I'm having a few problems with a shared access 97 db. I have the
database split with the tables on the server and everything else in
"client" front ends with links to the tables, e.g....
|
by: Arjen |
last post by:
Hi,
My experience with linq is that I can develop my web application very fast.
On the other hand, I have read that using stored procedures are executing
faster.
Is it smart to use linq for a...
|
by: taylorcarr |
last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
|
by: ryjfgjl |
last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
|
by: ryjfgjl |
last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: Sonnysonu |
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by column-wise with in the specific length.
suppose the i have to...
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
|
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...
|
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...
| |