473,910 Members | 6,771 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 1125
> 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
2375
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
2086
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
3814
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
1443
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
2003
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
2113
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
1167
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
5424
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
5502
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
1838
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
9879
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 synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
11349
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...
1
11055
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
10541
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
9727
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 launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
8099
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 instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5939
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
2
4337
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
3360
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.