[c#] Serializable practice1
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
32
33
34
35
36
37
38
39
40
41
|
using System;
using System.Collections.Generic;
using System.Text;
using System.Threading.Tasks;
using System.Xml.Serialization;
using System.IO;
namespace ConsoleApplication6
{
[Serializable]
public class Student
{
public string Id { get; set; }
public string Name { get; set; }
public string PhoneNumber { get; set; }
}
class Program
{
static void Main(string[] args)
{
List<Student> list = new List<Student>();
list.Add(new Student() { Id = "001", Name = "KIM", PhoneNumber = "010-0000-0001" });
list.Add(new Student() { Id = "002", Name = "SIM", PhoneNumber = "010-1234-2341" });
list.Add(new Student() { Id = "003", Name = "JIN", PhoneNumber = "010-1345-1231" });
list.Add(new Student() { Id = "004", Name = "JOO", PhoneNumber = "010-9999-4531" });
XmlSerializer s = new XmlSerializer(typeof(List<Student>));
//현재디렉토리에..
StreamWriter w = new StreamWriter(System.Environment.CurrentDirectory + "myTest.xml");
s.Serialize(w, list);
}
}
}
| cs |
댓글
댓글 쓰기