Click here to Skip to main content
15,895,557 members
Articles / Programming Languages / C#

Achieve Persistence Through Serialization

Rate me:
Please Sign up or sign in to vote.
4.60/5 (7 votes)
6 Jan 2011CPOL5 min read 29.7K   342   15  
This article compares the two common types of serialization in aspects of data access, readability, and runtime cost.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Reflection;
using System.Drawing;
using System.Xml.Serialization;

namespace Trestan
{
    class Program
    {
        static void Main(string[] args)
        {
            Console.WriteLine("Normally we will create GUI for user interaction. Here we just use console as a demo.\n");
            Console.WriteLine("Configuration settings:\n");
            Console.WriteLine("ServerIP: "+Configuration.Instance.ServerIP);
            Console.WriteLine("ServerPort: " + Configuration.Instance.ServerPort);
            Console.WriteLine("UserName: " + Configuration.Instance.CurrentUser.UserName);
            Console.WriteLine("UserID: " + Configuration.Instance.CurrentUser.UserID);
            Console.WriteLine("\nPlease input user name: ");
            Configuration.Instance.CurrentUser.UserName = Console.ReadLine();
            Configuration.Instance.CurrentUser.UserID = 1001;   //In real application, this value will be obtained from server side after athentication.
            Configuration.Instance.ServerIP = Utility.getHostIP();
            Configuration.Instance.Save();

            Console.WriteLine("Press enter to exit. Run the program again will show new settings.");
            Console.Read();
        }
    }
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Team Leader
Canada Canada
Looking for something to do in the new year.

Comments and Discussions