티스토리 뷰
List<string> 객체도 XML Serialization이 가능하다.
아래는 그 예제이다.
별로 어렵지 않은 예제이니 잘 살펴보기 바란다.
using System;
using System.Collections.Generic;
using System.Xml;
using System.Xml.Serialization;
namespace SerializationTest
{
class Program
{
static void Main(string[] args)
{
List<string> myList = new List<string>();
myList.Add("One");
myList.Add("Two");
myList.Add("Three");
XmlSerializer myXmlSerializer = new XmlSerializer(typeof(List<string>));
using (XmlWriter writer = XmlWriter.Create("serialization.xml"))
{
myXmlSerializer.Serialize(writer, myList);
}
List<string> yourList;
using (XmlReader reader = XmlReader.Create("serialization.xml"))
{
object o = myXmlSerializer.Deserialize(reader);
yourList = o as List<string>;
}
foreach (string item in yourList)
{
Console.WriteLine(item);
}
}
}
}
아래는 실행 결과 화면이다.
Deserialize가 정상적으로 이루어졌다.
아래는 그 예제이다.
별로 어렵지 않은 예제이니 잘 살펴보기 바란다.
using System;
using System.Collections.Generic;
using System.Xml;
using System.Xml.Serialization;
namespace SerializationTest
{
class Program
{
static void Main(string[] args)
{
List<string> myList = new List<string>();
myList.Add("One");
myList.Add("Two");
myList.Add("Three");
XmlSerializer myXmlSerializer = new XmlSerializer(typeof(List<string>));
using (XmlWriter writer = XmlWriter.Create("serialization.xml"))
{
myXmlSerializer.Serialize(writer, myList);
}
List<string> yourList;
using (XmlReader reader = XmlReader.Create("serialization.xml"))
{
object o = myXmlSerializer.Deserialize(reader);
yourList = o as List<string>;
}
foreach (string item in yourList)
{
Console.WriteLine(item);
}
}
}
}
아래는 실행 결과 화면이다.
Deserialize가 정상적으로 이루어졌다.
'Code > C#' 카테고리의 다른 글
Generic Dictionary Xml Serialization C# Example 1 (0) | 2007.12.16 |
---|---|
DateTime 이 포함된 객체의 Serialization (0) | 2007.12.15 |
XML Serialization 사용법과 예제 (0) | 2007.12.15 |
Path 클래스를 사용해서 원하는 파일의 위치를 지정하는 방법 (0) | 2007.12.15 |
Windows Form Application의 Path를 구하는 방법 (0) | 2007.12.15 |
공지사항
최근에 올라온 글
최근에 달린 댓글
- Total
- Today
- Yesterday
링크
TAG
- tagREADYSTATE
- AdSense숨기기
- 애드센스숨기기
- windows
- ScreenHunter
- 애드센스감추기
- Regular Expressions
- AxWebBrowser
- c#
- WinAutomation
- READYSTATE_COMPLETE
- java
- 스크린캡쳐
- Service pack
- Sample Code
- 유틸리티
- Automation
- jre
- iTextSharp
- AdSense감추기
- download.com
- Rollback Rx
- Microsoft
- registry
- autohotkey
- DotNetMagic
- iText
- Phalanger
- .net framework
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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 |
글 보관함