473,566 Members | 2,763 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Static Method Parameters issue

Hi,

Mine is a very basic doubt ...

(1) If we are using a static field/object, then the field/object is shared
across all the places in the entire application as it is stored only at one
place.
(2) If it is an instance-based object, then when each instance gets created,
a new memory space gets allocated to every instance.

Now coming to methods,
(3) In the case of instance-based methods, there will be only copy of the
method existing in the memory (yes only one irrespective of the number of
instances using it). This is so because, there will be an instance
intrinsically passed to this instance-based method (we need not specify
this). This implicitly passed parameter is 'this' in C# and 'Me' in VB .NET
which refers to the instance calling that method. The method then operates on
this instance passed.
(4) The case is same in the case of static methods also except that the
implicit 'this' or 'Me' wont be passed. Now for my question: In this static
method, how are the parameters stored ... specifically when multiple objects
calls this instance-based method passing different parameters, then is there
any risk of corruption or how does this work??

Kindly correct me if I'm wrong anywhere...

Thanks in advance.
--
Samba!

Aug 2 '05 #1
2 2063
check out this link which clearly explains how parameters are stored and
evaluated for static functions..Hope this will give u an better idea...
http://msdn.microsoft.com/library/de...spec_7_4_1.asp

"Samba" wrote:
Hi,

Mine is a very basic doubt ...

(1) If we are using a static field/object, then the field/object is shared
across all the places in the entire application as it is stored only at one
place.
(2) If it is an instance-based object, then when each instance gets created,
a new memory space gets allocated to every instance.

Now coming to methods,
(3) In the case of instance-based methods, there will be only copy of the
method existing in the memory (yes only one irrespective of the number of
instances using it). This is so because, there will be an instance
intrinsically passed to this instance-based method (we need not specify
this). This implicitly passed parameter is 'this' in C# and 'Me' in VB .NET
which refers to the instance calling that method. The method then operates on
this instance passed.
(4) The case is same in the case of static methods also except that the
implicit 'this' or 'Me' wont be passed. Now for my question: In this static
method, how are the parameters stored ... specifically when multiple objects
calls this instance-based method passing different parameters, then is there
any risk of corruption or how does this work??

Kindly correct me if I'm wrong anywhere...

Thanks in advance.
--
Samba!

Aug 2 '05 #2
Samba <sr****@dotnet. microsoft.com> wrote:
Mine is a very basic doubt ...

(1) If we are using a static field/object, then the field/object is shared
across all the places in the entire application as it is stored only at one
place.
(2) If it is an instance-based object, then when each instance gets created,
a new memory space gets allocated to every instance.

Now coming to methods,
(3) In the case of instance-based methods, there will be only copy of the
method existing in the memory (yes only one irrespective of the number of
instances using it). This is so because, there will be an instance
intrinsically passed to this instance-based method (we need not specify
this). This implicitly passed parameter is 'this' in C# and 'Me' in VB .NET
which refers to the instance calling that method. The method then operates on
this instance passed.
What do you mean by "copy of the method"? You need to be *very* clear
as to what you mean by that - I suspect that when you try to explain
it, you'll find the problem goes away.
(4) The case is same in the case of static methods also except that the
implicit 'this' or 'Me' wont be passed. Now for my question: In this static
method, how are the parameters stored ... specifically when multiple objects
calls this instance-based method passing different parameters, then is there
any risk of corruption or how does this work??


Parameters are stored on the stack, whether for instance methods or
static methods. They don't interfere with each other (although if those
parameters are references to other objects, then things become a bit
more complicated, of course).

--
Jon Skeet - <sk***@pobox.co m>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Aug 2 '05 #3

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

Similar topics

4
1859
by: Dave | last post by:
I used the following class and .aspx code below to understand how static works on variables and methods taken from "http://msdn.microsoft.com/library/default.asp?url=/library/en-us/csref/html/vclrfstaticpg.asp". I opened up two instances of my browser to simulate two users accessing the page at the same time by pointing to Employee.aspx...
2
2648
by: superseed | last post by:
Hi, I'm pretty new to C#, and I'm quite stuck on the following problem. I would like to add to my application a Windows.Form (singleton) on which I could display a message of one of the following type : Exception, Error, Warning, Infos (with differents colors, etc). I would like to use it like the Console.WriteLine("My Message"); on...
2
239
by: Samba | last post by:
Hi, Mine is a very basic doubt ... (1) If we are using a static field/object, then the field/object is shared across all the places in the entire application as it is stored only at one place. (2) If it is an instance-based object, then when each instance gets created, a new memory space gets allocated to every instance.
5
6262
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
11
3809
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...
12
3559
by: chandu | last post by:
hello, i want to know usage of static methods in a class. is it advantageous or disadvantage to use more static methods in a class. thank u
55
6171
by: Zytan | last post by:
I see that static is more restricted in C# than in C++. It appears usable only on classes and methods, and data members, but cannot be created within a method itself. Surely this is possible in C# in some way? Or maybe no, because it is similar to a global variable (with its scope restricted) which C# is dead against? Zytan
1
3516
by: Sandro Bosio | last post by:
Hello everybody, my first message on this forum. I tried to solve my issue by reading other similar posts, but I didn't succeed. And forgive me if this mail is so long. I'm trying to achieve the following (with incomplete succes): I want in a given namespace Parameters a list of "initializers" (which are objects derived from a simple interface...
9
5833
by: Steve Richter | last post by:
in a generic class, can I code the class so that I can call a static method of the generic class T? In the ConvertFrom method of the generic TypeConvert class I want to write, I have a call to the static Parse method of the conversion class. if (InValue is string) return T.Parse((string)InValue); else return base.ConvertFrom(context,...
0
7666
marktang
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...
0
7584
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...
0
7888
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
1
7644
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
6260
agi2029
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...
1
5484
isladogs
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...
0
3626
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2083
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1201
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.