-
03/17 List<T> 변수 선언, 인스턴스 생성, 값 할당, 출력 복습C#/수업내용 2021. 3. 17. 10:09
Program.cs
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace Study06 { class Program { static void Main(string[] args) { Console.WriteLine("Main"); new App(); } } }
App.cs
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace Study06 { public class App { public App() { Console.WriteLine("App"); //List<string> 변수 선언 List<string> listStr; //List<string> 인스턴스 및 변수에 할당 listStr = new List<string>(); //List<string> 요소에 값 추가 listStr.Add("장검"); listStr.Add("단검"); listStr.Add("활"); listStr.Add("창"); listStr.Add("지팡이"); //List<string> 의 요소의 수 출력 Console.WriteLine("\nList<string> 의 요소의 수 출력 : " + listStr.Count); //foreach문을 사용해 List<string>의 요소 출력 Console.WriteLine("\nforeach문을 사용해 List<string>의 요소 출력"); foreach(string str in listStr) { Console.WriteLine(str); } } } }
'C# > 수업내용' 카테고리의 다른 글
03/17 배열 변수 선언, 인스턴스 생성, 값 할당, 출력 복습 2 (0) 2021.03.17 03/17 Dictionary 변수 선언, 인스턴스 생성, 값 할당, 출력 복습 (0) 2021.03.17 03/17 배열 변수 선언, 인스턴스 생성, 값 할당, 출력 복습 (0) 2021.03.17 03/16 수업내용 메모 (0) 2021.03.17 03/16 List<T> 를사용한 인벤토리 제작 연습 (0) 2021.03.16