일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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 |
- 인스톨
- 데이터베이스
- WIN32 SDK
- xml
- c#
- MFC
- SQL
- 소니
- Visual Studio 2005
- 초보
- dll
- winsock
- vb
- 기초
- Visual Basic
- 델파이
- MySQL
- 파이어버드
- PostgreSQL
- 시리얼 통신
- VB.NET
- 입문
- 문자열
- SDK
- 설치
- Delphi
- 예제
- Firebird
- 파라미터
- 셋업
- Today
- Total
프로그래밍 노트
[C#] List에서 Array로 복사하기/ Array를 List로 복사하기 본문
using System;
using System.Collections.Generic;
using System.Linq;
using System.Windows.Forms;
namespace ListToArray
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
/// <summary>
/// List를 Array로 복사
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void btnListToArray_Click(object sender, EventArgs e)
{
List<Test> testList = new List<Test>();
Test test = new Test();
test.name = "aaa";
test.weight = 50.3;
testList.Add(test);
test.name = "bbb";
test.weight = 77.7;
testList.Add(test);
test.name = "ccc";
test.weight = 65.3;
testList.Add(test);
Test[] testArray = testList.ToArray();
}
/// <summary>
/// Array를 List로 복사
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void btnArrayToList_Click(object sender, EventArgs e)
{
Test[] testArray = new Test[3];
Test test = new Test();
test.name = "aaa";
test.weight = 50.3;
testArray[0] = test;
test.name = "bbb";
test.weight = 77.7;
testArray[1] = test;
test.name = "ccc";
test.weight = 65.3;
testArray[2] = test;
List<Test> testList = testArray.ToList();
}
}
internal class Test
{
public string name { get; set; }
public double weight { get; set; }
}
}