473,386 Members | 1,705 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

Shared Procedures Query

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
Nov 21 '05 #1
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.
Nov 21 '05 #2
> 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

Nov 21 '05 #3
> 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

Nov 21 '05 #4
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


Nov 21 '05 #5
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.


Nov 21 '05 #6

"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.
Nov 21 '05 #7
"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/>

Nov 21 '05 #8
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/>

Nov 21 '05 #9

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

10
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,...
1
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...
4
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...
6
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...
7
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,...
6
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...
45
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
5
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....
6
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...
0
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,...
0
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...
0
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...
0
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
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
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...
0
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...
0
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...
0
jinu1996
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...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.