473,395 Members | 1,437 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,395 software developers and data experts.

XML weird ??

hi all

here my situation :

public class A
{
XmlDocument m_xmlDocument=null;
public A()
{
this.createEmptyXMLDocument();
// create an empty XMLdocument with XMLDeclaration and
// root Element into x_xmlDocument variable

}

// got a button ----
private void btn_new_click(object sender,System.EvenArgs e)
{
// add new employee
this.addEmployee(this.m_xmlDocument,strFirstname);
}
private addEmployee(XMLDocument doc,string firstname)
{
....... Do something to add new child into "doc" ;
}

}

What i got here is that, not just "doc" is added new child, "m_xmlDocument"
also is added new child , just the same as doc.
As far as i know, there's no way that can happen ....

Thanks,


Nov 29 '05 #1
8 1105
> As far as i know, there's no way that can happen ....
Surely that happens. You pass a reference type as pamameter, then
modify its content. doc and m_xmlDocument reference the same memory
location, as the result, the child is inserted into m_xmlDocument. I
suggest you consult documentation about passing reference type as
parameter.

Thi - http://thith.blogspot.com

Nov 29 '05 #2
How about this situation ??

public class A
{
int i=0;
public A()
{

}
private void btn_plus_click(object sender,System.EvenArgs e)
{
this.plus(i,2);
// i is still 0 here ;
}
public void plus(int a,int b)
{
a=a+b;
}
}

"Truong Hong Thi" <th*****@gmail.com> wrote in message
news:11**********************@g49g2000cwa.googlegr oups.com...
As far as i know, there's no way that can happen ....

Surely that happens. You pass a reference type as pamameter, then
modify its content. doc and m_xmlDocument reference the same memory
location, as the result, the child is inserted into m_xmlDocument. I
suggest you consult documentation about passing reference type as
parameter.

Thi - http://thith.blogspot.com

Nov 29 '05 #3
Hi,

int (or System.Int32 what it really is) is a value type. Value types are
passed by value and not by reference.

You might want to read MSDN on value and reference types. For example,
there is an article about it in MSDN Magazine.

http://msdn.microsoft.com/msdnmag/issues/1200/dotnet/

Or check out other articles, you can find a lot with Google. For example:

http://www.knowdotnet.com/articles/referencetypes2.html
-Lenard

Vuong wrote:
How about this situation ??

public class A
{
int i=0;
public A()
{

}
private void btn_plus_click(object sender,System.EvenArgs e)
{
this.plus(i,2);
// i is still 0 here ;
}
public void plus(int a,int b)
{
a=a+b;
}
}

"Truong Hong Thi" <th*****@gmail.com> wrote in message
news:11**********************@g49g2000cwa.googlegr oups.com...
As far as i know, there's no way that can happen ....


Surely that happens. You pass a reference type as pamameter, then
modify its content. doc and m_xmlDocument reference the same memory
location, as the result, the child is inserted into m_xmlDocument. I
suggest you consult documentation about passing reference type as
parameter.

Thi - http://thith.blogspot.com


Nov 29 '05 #4
Yes, because int is of value type. XmlDocument is reference type. There
are many good articles on C# parameter passing. Do a search with your
favorite search engine.

Nov 29 '05 #5
Yep
A very basic problem, a really big deal.

See ya

"Lenard Gunda" <ar***********@freemail.hu> wrote in message
news:Om**************@TK2MSFTNGP12.phx.gbl...
Hi,

int (or System.Int32 what it really is) is a value type. Value types are
passed by value and not by reference.

You might want to read MSDN on value and reference types. For example,
there is an article about it in MSDN Magazine.

http://msdn.microsoft.com/msdnmag/issues/1200/dotnet/

Or check out other articles, you can find a lot with Google. For example:

http://www.knowdotnet.com/articles/referencetypes2.html
-Lenard

Vuong wrote:
How about this situation ??

public class A
{
int i=0;
public A()
{

}
private void btn_plus_click(object sender,System.EvenArgs e)
{
this.plus(i,2);
// i is still 0 here ;
}
public void plus(int a,int b)
{
a=a+b;
}
}

"Truong Hong Thi" <th*****@gmail.com> wrote in message
news:11**********************@g49g2000cwa.googlegr oups.com...
As far as i know, there's no way that can happen ....

Surely that happens. You pass a reference type as pamameter, then
modify its content. doc and m_xmlDocument reference the same memory
location, as the result, the child is inserted into m_xmlDocument. I
suggest you consult documentation about passing reference type as
parameter.

Thi - http://thith.blogspot.com


Nov 29 '05 #6
Yep
A very basic problem, a really big deal.

See ya

"Truong Hong Thi" <th*****@gmail.com> wrote in message
news:11*********************@o13g2000cwo.googlegro ups.com...
Yes, because int is of value type. XmlDocument is reference type. There
are many good articles on C# parameter passing. Do a search with your
favorite search engine.

Nov 29 '05 #7
Lenard Gunda wrote:
int (or System.Int32 what it really is) is a value type. Value types are
passed by value and not by reference.


Whoa there - both reference type expressions and value type expressions
are passed by value by default. It's just that with reference type
expressions, the actual object is not passed at all - only a reference
is passed.

It's very important to maintain a distinction between passing a
reference by value and passing a value by reference.

See http://www.pobox.com/~skeet/csharp/parameters.html

Even if Int32 were a reference type, the "plus" method given wouldn't
change the passed value, because:

a = a+b;

would change the value of the (local) variable a, it wouldn't change
any data within the object which a originally referred to.

(Try it using strings instead of ints - string is a reference type.)

Jon

Nov 29 '05 #8
>Even if Int32 were a reference type, the "plus" method given wouldn't
change the passed value.

Ah, yes. I did not paid much attention to the snippet. Int32 is just as
immutable as string. It does not expose any methods allowing its
contents to be modified.

Dec 1 '05 #9

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

Similar topics

2
by: Gabriel Afana | last post by:
I have a simple php script to just send email.....When I first load the script in a browser...it sends 2 emails. Why?? The weird thing is then when I refresh the page, it send only one email...I...
3
by: redneck_kiwi | last post by:
Hi all: I have a really weird problem. I am developing a customer catalog system for my company and as such have delved into sessions for authentication and access levels. So far, I have managed...
13
by: Wolfgang Kaml | last post by:
Hello All, I have been researching newsgroups and knowledgebase all morning and not found a solution that would solve the problem I have. I am having an ASP or ASPX web page that implement a...
0
by: LRW | last post by:
I manage our mySQL database through putty (SSH terminal client). And whenever I do a select * from the table that contains ENCODEd passwords, the funky characters do funky things with the display....
2
by: jwbeaty | last post by:
Here's a weird one. I'm running SQL Server 7 and when I run a backup something weird happens. When I perform the backup via Enterprise Manager by right clicking on the database I want to...
1
by: Kaneda | last post by:
Hello everyone! I have some weird(?) problems, and I am not quite sure if there are due to my errors or maybe a limitation in the .Net framework. I have a ComboBox I need to fill with the...
0
by: Kaneda | last post by:
Hello everyone! I have some weird(?) problems, and I am not quite sure if there are due to my errors or maybe a limitation in the .Net framework. I have a ComboBox I need to fill with the...
82
by: nobody | last post by:
Howdy, Mike! mikecoxlinux@yahoo.com (Mike Cox) wrote in message news:<3d6111f1.0402271647.c20aea3@posting.google.com>... > I'm a C++ programmer, and have to use lisp because I want to use >...
3
by: aling | last post by:
Execute following T-SQL within Queary Analyzer of SQL Server 2000: ======================================= DECLARE @dTest DATETIME SET @dTest='2001-1-1 1:1:1:991' SELECT @dTest SET...
0
by: P Pulkkinen | last post by:
Dear all, sorry, i know this code is far little too long to debug here, but there is really annoying logical error. If someone debugs this, I really offer warm virtual handshake. What this...
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: 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
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
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
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,...
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
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,...
0
tracyyun
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...

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.