•
•
•
•
What is DaniWeb IT Discussion Community?
You're currently browsing the C# section within the Software Development category of DaniWeb, a massive community of 456,504 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 2,666 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our C# advertiser: Programming Forums
Views: 1154 | Replies: 1
![]() |
•
•
Join Date: Dec 2006
Posts: 31
Reputation:
Rep Power: 2
Solved Threads: 0
hi,
im using this code to serialize my class into xml:
my class has only 2 things to serialize. these are private member variables, which i provide access to via public properties:
both _MyStringList and _MyString are initialized in the constructor. but only _MyStringList gets serialized. why does the list of strings get seriaslized but not the string?
if i make _MyString (the actual private variable) public, then all works well. but i dont want public members vars.
if i set the private _MyString variable through the public MyString property *before* serializing, then this works too. i would just like to know why i simply cannot intiialize the private member in the constructor and then this value is serialized.
thanks.
im using this code to serialize my class into xml:
public static void Save(Class1 myClass) { System.Xml.XmlTextWriter w = new System.Xml.XmlTextWriter(@"./myFile.cfg", Encoding.ASCII); System.Xml.Serialization.XmlSerializer x = new System.Xml.Serialization.XmlSerializer(myClass.GetType()); x.Serialize(w, myClass); w.Close(); }
my class has only 2 things to serialize. these are private member variables, which i provide access to via public properties:
/* private vars */ private List<string> _MyStringList = new List<string>(); _MyStringList.Add private string _MyString; /* public properties */ public string MyString { get { return _MyString; } set { _MyString = value; } } public List<string> MyStringList { get { return _MyStringList; } set { _MyStringList= value; } }
both _MyStringList and _MyString are initialized in the constructor. but only _MyStringList gets serialized. why does the list of strings get seriaslized but not the string?
if i make _MyString (the actual private variable) public, then all works well. but i dont want public members vars.
if i set the private _MyString variable through the public MyString property *before* serializing, then this works too. i would just like to know why i simply cannot intiialize the private member in the constructor and then this value is serialized.
thanks.
![]() |
•
•
•
•
•
•
•
•
DaniWeb C# Marketplace
•
•
•
•
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
Similar Threads
- Windows Explorer Issue: my "Address" bar is gone, how do I get it back? (Windows NT / 2000 / XP / 2003)
- Power boot up issue (Motherboards, CPUs and RAM)
- Getting Windows to see a SATA drive (Storage)
- BitchX + Terminal issue (Mac Software)
- Kernel Version of Mandrake and error message (*nix Software)
- Memory Issue's! Please Help!! (Motherboards, CPUs and RAM)
- Internet Explorer Connection Issue (Web Browsers)
- Netgear router issue...read this if you have one (Networking Hardware Configuration)
Other Threads in the C# Forum
- Previous Thread: Help regarding cell click event in datagridview
- Next Thread: i cant save data on an access database


Linear Mode