473,695 Members | 2,497 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

XML weird ??

hi all

here my situation :

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

}

// got a button ----
private void btn_new_click(o bject sender,System.E venArgs e)
{
// add new employee
this.addEmploye e(this.m_xmlDoc ument,strFirstn ame);
}
private addEmployee(XML Document 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_xmlDocum ent"
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 1115
> 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.E venArgs 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.goo glegroups.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.E venArgs 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.goo glegroups.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******** ******@TK2MSFTN GP12.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.E venArgs 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.goo glegroups.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******** *************@o 13g2000cwo.goog legroups.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
2361
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 can refresh the page a million times and each time it only sends 1 email. But its the first time the page is loaded (like I open a new IE browser and go to the script), it sends 2 emails (duplicates). The entire script is below: <?php $to...
3
2076
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 to get a working system just about finished. I am building an interface for our customer service folks to use to manage registered customers and am seeing some weird behavior.
13
3800
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 counter functionality and read/insert some data in a MS Access database on that Windows 2003 server. The weird part is, as long as the web page is very short in size, I can hit the refresh button and Internet Explorer will reload the page and display...
0
1431
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. From doing weird alignment things, to making it so that so long as those characters are visible, the display is always scrolled to a line where one of those screwy ASCII characters are. I can scroll up or down, but as soon as I type something on...
2
1991
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 backup, I click on OK but no progress blocks show up in the window showing you the status of the backup. The completion window pops up saying that the DB has been backed up. OK--Fine, maybe the backup is really quick. Then, through Explorer, I look...
1
2101
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 content of an untyped DataSet. This is to be done in the "DropDown" Event (since the dataset is empty at program start). If I go with this:
0
1153
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 content of an untyped DataSet. This is to be done in the "DropDown" Event (since the dataset is empty at program start). If I go with this:
82
5341
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 > emacs. I've gotten a book on lisp, and I must say lisp is the ugliest > looking language syntax wise. What is up with this: (defun(foo()). (DEFUN FOO () NIL) > What were the lisp authors thinking? Why did Stallman use lisp in
3
5478
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 @dTest='2001-1-1 1:1:1:997' SELECT @dTest
0
1826
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 code SHOULD do: - read new (=updated) licensetext from file $license_path then - read and modify recursively all files from $current_dir, replacing old
0
8639
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 usage, and What is the difference between ONU and Router. Letís take a closer look ! Part I. Meaning of...
0
9120
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. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8999
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8858
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 most users, this new feature is actually very convenient. If you want to control the update process,...
0
8832
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
5841
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4586
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
2279
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
1980
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.