Program.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Xml.Linq;
namespace LinqXML
{
class Program
{
static void Main(string[] args)
{
// 데이터 생성
List<person> listPerson = new List<person>(){
new Person{ Name = "아저씨", Age="30"},
new Person{ Name= "아줌마", Age="34"},
};
// LINQ
var personToXML = new XElement("Root",
from person in listPerson
select new XElement("person",
new XElement("Name", person.Name),
new XElement("Age", person.Age)
) // End "person"
); // End "Root"
Console.WriteLine(personToXML);
Console.ReadKey();
}
}
// Person
class Person
{
public string Name { get; set; }
public string Age { get; set; }
}
}실행결과
'프로그래밍 > .NET' 카테고리의 다른 글
| [ASP.NET] TextBox 입력시 다른 컨트롤 이벤트 발생시키기 (0) | 2013.09.11 |
|---|---|
| [ASP.NET]페이지 로드 후 몇초 후 다른 페이지로 이동 (0) | 2013.05.14 |
| [C#]IP 주소 얻기 (0) | 2013.05.14 |
| [C#]string -> DateTime (0) | 2013.05.08 |
| [C#]수행 시간측정 (0) | 2013.04.16 |