Simple C# program question

jeffiepoo
jeffiepoo used Ask the Experts™
on
Experts,

I'm new to C#, but I'm really good with java so I thought I would familiarize myself with C# by doing a simple project. There is one MAJOR thing I need information about, and I'm going to ask you guys.

For programs in the past and in school, we would write our own data structures. These structures would be filled either by parsing input or files or whatever.

I want this program to SAVE the data in it's data structure, so when it loads up the data is already in the program.

I need a SIMPLE AS PIE way to do this. I do not want to write a program that outputs everything to a specific format that I've developed myself and then parses the information later. In other words, I want a library of data structures that has this functionality (or any other way to do this is fine).

I don't know much about databases, but if there is a database I could use to save info then output to a file, then use it to read the file into the program again or something? I don't have a web server or anything to host anything btw.

Any recommendations would be awesome! Thanks guys!

-Jeff
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Commented:
The simplist way is going to be to serialise the objects to and from a file... this does not provide all of the benefits of a database but  seeing as you want the quickest solution it's a starting point.

This article should give you a good starting point:

http://www.switchonthecode.com/tutorials/csharp-tutorial-serialize-objects-to-a-file

Commented:
Well, I suppose this is heavily stipulated by the type of data and what you want to do with the data.

Arguably, the "simplest" way would be to use application settings
http://msdn.microsoft.com/en-us/library/k4s6c3a0.aspx

You can store user/application specific settings which you can load in to your application.  The settings persist between execution, and provide a relatively simple way to save/edit some types of data.

Alternatively, besides using a database, .NET provides all kinds of great facilities for working with XML files.  You can generate and manipulate XML files with relative ease.  Using Linq-to-XML makes the process all the simpler.

Author

Commented:
Looks like a WONDERFUL suggestion thanks.

One question:

Have you used this?

If so, in the example, could I make my "public class ObjectToSerialize" class a fully functional class that holds all my data (private data structures) with getter/setter methods, a constructor, ect. And just serialize it like the rest of the example shows.

Is it really this simple? If so that is awesome. Do you know of any equivalent things in Java?

-Jeff
Success in ‘20 With a Profitable Pricing Strategy

Do you wonder if your IT business is truly profitable or if you should raise your prices? Learn how to calculate your overhead burden using our free interactive tool and use it to determine the right price for your IT services. Start calculating Now!

Author

Commented:
Also,

What is the second part of the code below, it looks like a getter and setter for the list? What else can this notation be used on? Is it standard?

   private List<Car> cars;

   public List<Car> Cars
   {
      get { return this.cars; }
      set { this.cars = value; }
   }

After this I'm done asking new questions. Thanks guys,

-Jeff
Top Expert 2009
Commented:
Yep its really that simple. .NET keeps you from reinventing the wheel with serializing objects, as well as config tracking in your applications.
Top Expert 2009

Commented:
That is standard property notation. So you can use

obj.Cars = ...

Instead of obj.setCars(...)

Another lesson that C# team learned from Java/C++

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial