티스토리 뷰
앞에서 보였던 GenericDictionaryXmlSerializer 클래스 2 사용 예제이다.
using System;
using System.Collections.Generic;
using System.Xml;
using GenericDictionaryXmlSerialization;
namespace TestGenericDictionaryXmlSerialization
{
class Program
{
static void Main(string[] args)
{
Random myRandom = new Random();
Dictionary<string, int> myDictionary = new Dictionary<string, int>();
myDictionary["1st"] = myRandom.Next(10);
myDictionary["2nd"] = myRandom.Next(10);
myDictionary["3rd"] = myRandom.Next(10);
myDictionary["4th"] = myRandom.Next(10);
GenericDictionaryXmlSerializer<string, int> mySerializer = new GenericDictionaryXmlSerializer<string, int>();
using (XmlWriter writer = XmlWriter.Create("serialization.xml"))
{
mySerializer.Serialize(writer, myDictionary);
}
Dictionary<string, int> yourDictionary = new Dictionary<string, int>();
using (XmlReader reader = XmlReader.Create("serialization.xml"))
{
yourDictionary = mySerializer.Deserialize(reader);
}
foreach (KeyValuePair<string, int> item in yourDictionary)
{
Console.WriteLine(item.Key + " : " + item.Value.ToString());
}
}
}
}
using System;
using System.Collections.Generic;
using System.Xml;
using GenericDictionaryXmlSerialization;
namespace TestGenericDictionaryXmlSerialization
{
class Program
{
static void Main(string[] args)
{
Random myRandom = new Random();
Dictionary<string, int> myDictionary = new Dictionary<string, int>();
myDictionary["1st"] = myRandom.Next(10);
myDictionary["2nd"] = myRandom.Next(10);
myDictionary["3rd"] = myRandom.Next(10);
myDictionary["4th"] = myRandom.Next(10);
GenericDictionaryXmlSerializer<string, int> mySerializer = new GenericDictionaryXmlSerializer<string, int>();
using (XmlWriter writer = XmlWriter.Create("serialization.xml"))
{
mySerializer.Serialize(writer, myDictionary);
}
Dictionary<string, int> yourDictionary = new Dictionary<string, int>();
using (XmlReader reader = XmlReader.Create("serialization.xml"))
{
yourDictionary = mySerializer.Deserialize(reader);
}
foreach (KeyValuePair<string, int> item in yourDictionary)
{
Console.WriteLine(item.Key + " : " + item.Value.ToString());
}
}
}
}
'Code > C#' 카테고리의 다른 글
PInvoke SetForegroundWindow Sample Code (0) | 2008.01.14 |
---|---|
Process Class Sample Code 1 (0) | 2008.01.14 |
Generic Dictionary Xml Serialization C# Example 2 (0) | 2007.12.16 |
Generic Dictionary Xml Serialization C# Example 1 (0) | 2007.12.16 |
DateTime 이 포함된 객체의 Serialization (0) | 2007.12.15 |
공지사항
최근에 올라온 글
최근에 달린 댓글
- Total
- Today
- Yesterday
링크
TAG
- 애드센스숨기기
- 애드센스감추기
- Automation
- Regular Expressions
- Phalanger
- ScreenHunter
- iTextSharp
- Rollback Rx
- c#
- windows
- registry
- 스크린캡쳐
- 유틸리티
- Microsoft
- AdSense감추기
- Service pack
- iText
- READYSTATE_COMPLETE
- jre
- java
- AdSense숨기기
- Sample Code
- download.com
- DotNetMagic
- WinAutomation
- AxWebBrowser
- autohotkey
- .net framework
- tagREADYSTATE
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | 4 | 5 | 6 | |
7 | 8 | 9 | 10 | 11 | 12 | 13 |
14 | 15 | 16 | 17 | 18 | 19 | 20 |
21 | 22 | 23 | 24 | 25 | 26 | 27 |
28 | 29 | 30 |
글 보관함