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! 2 2045
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!
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.com> http://www.pobox.com/~skeet
If replying to the group, please do not mail me too This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
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...
|
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...
|
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...
|
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...
|
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
|
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...
|
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...
|
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...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...
|
by: ryjfgjl |
last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: aa123db |
last post by:
Variable and constants
Use var or let for variables and const fror constants.
Var foo ='bar';
Let foo ='bar';const baz ='bar';
Functions
function $name$ ($parameters$) {
}
...
|
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: 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...
| |