Ouch I don't understand a bit of what you wrote, as I said I'm totally new to C#.
Main Topics
Browse All TopicsI'm pretty new to C# and need advise on how to Structure up code in a good way, making classes and methods.
Here is a small example code I wrote that I would like to structure better.
For example the xml node fetching is declared 2 times, when thay load on a button and when they are saved by another button.
How could I for example write a class or method that is located in a different .cs file and just call the method or class instead of writing the code several times ?
I also wonder how I can create the LocalTitle node directly under Root as the first child ?
As it is now I create LocalTitle node by saying that it should be added before OriginalTitle which is the firstchild, but if the OriginalTitle is missing then this wont work I guess.
Any examples ?
This Question has been solved and asker verified All Experts Exchange premium technology solutions are available to subscription members.
Experts Exchange has been collecting answers to technology questions since 1996…3 million and counting! If you have a question, chances are we already have your answer.
If you can't find the exact answer you're looking for, ask our exclusive community of 50,000 experts. You’ll get a personalized answer from a trusted professional.
Thousands of free tech tips, tricks, how-to’s and tutorials are available in our peer reviewed articles section. See for yourself how smart our experts are, no login required.
Access the answers to your technology questions today.
30-day free trial. Register in 60 seconds.
Members of the expert community talk about why the experience at Experts Exchange is different than what you will find anywhere else.

Try it out and discover for yourself.
30-day free trial. Register in 60 seconds.
Join the community of experts here and help other tech pros by answering question in your area of expertise. You can earn FREE access to all Experts Exchange's premium features and resources.
Thanks Tiggerito
This seems to be the right way, I have looked at some opensource application and they are written in this way.
Is there any chance that you could explain a bit more ?
Also I will be using a treeview that when selectedindex changes the path will be picked from the selected node to set the path to the xml file, how would I pull that to the save void ?
I'm not sure how I would go about using the get/set values.
Also could you tell me why you write this: public void Title() {}
Thanks !
Your indicating that the XML contains more than one instance of your Title item. i.e. there will be mutliple Title elements in the XML.
Could you comfirm this and provide a complete example of the XML that you will be working with.
The get; set; is automaitic in .Net 3.5 and is just a way to say a property that has a private field.
I stated the default constructor i.e. Title() as you heave to implicetly specify it if other constructors are specified.
Here is a copy/paste of a mymovies.xml example file:
Below the Xml is my current source code for reading the xml file that is picked when a node in treeview is selected.
My problem is that I somehow have hard time to make a code simple or to put it in some classes, methods or/and into different .cs files, all my code is sadly in my form.cs file.
This looks awful and is not so good even if Im a total newbie to programming.
Any code example and explanation would be greatly appriciated !
I can't think of anything more valuable to a beginning C# programmer than the this book:
Design Patterns Explained: A New Perspective on Object-Oriented Design (Second Edition) by Alan Shalloway and James R. Trott
The web site for the book is here:
http://www.netobjectives.c
I would advise buying it and making the commitment to working through it.
David
You may want to consider .Nets built in way to convert objects to/from XML called XML Serialisation.
Heres an article that creates several classes for data and serialises them
http://www.builderau.com.a
And some other articles that look good
http://www.c-sharpcorner.c
http://www.codeguru.com/co
http://msdn.microsoft.com/
Business Accounts
Answer for Membership
by: anyoneisPosted on 2009-04-25 at 17:40:42ID: 24234087
Well, the first thing that comes to mind is to create a specialized version of XmlDocument by deriving your own MediaDocument from it. That said, you should "prefer containment to inheritance."
This latter path would have you create a similar MediaDocument with similar methods and properties, but rather than inherit from XmlDocument, it would contain an XmlDocument field, and its methods and properties would forward calls to the contained XmlDocument as needed.
David