티스토리 뷰
앞에서 보였던 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
- iText
- windows
- Rollback Rx
- download.com
- AxWebBrowser
- 애드센스숨기기
- Microsoft
- Service pack
- Sample Code
- autohotkey
- .net framework
- registry
- c#
- Regular Expressions
- READYSTATE_COMPLETE
- ScreenHunter
- tagREADYSTATE
- iTextSharp
- jre
- 애드센스감추기
- 스크린캡쳐
- AdSense감추기
- 유틸리티
- AdSense숨기기
- DotNetMagic
- Automation
- Phalanger
- WinAutomation
- java
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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 |
31 |
글 보관함