19.03.27 반복문 사용 배열 출력 (for,foreach,while)

개임개발/수업내용 2019. 3. 27. 14:42
728x90
반응형
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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
 
namespace study_05
{
    class Unit
    {
        private string v;
 
        public Unit()
        {
 
            
            
            Unit[] array = new Unit[5];
 
            
 
            int[] arr0 = new int[5]; //000000000,int는 값형식이라 0
            Unit[] units = new Unit[5]; //null, 클래스는 참조형식이라 null
            //배열은 array클래스에서 파생된 형식이고, 참조형식이라 null 이다.
            string[] arrNames = { "홍길동""임꺽정""홍상직" };  //배열의 인스턴스
 
 
         
 
 
            for (int i = 0; i<units.Length; i++)
            {
                Unit unit = units[i];
                Console.WriteLine($"for문에서 나오는값 :{arrNames[i]}");
                Console.WriteLine($"for문에서 나오는값 :{arrNames[i+1]}");
                Console.WriteLine($"for문에서 나오는값 :{arrNames[i+2]}");
                break;
            }
            
            foreach (string Unit in arrNames)
            {
               
                System.Console.WriteLine($"foreach문에서 나오는값 :{arrNames[0]}");
                System.Console.WriteLine($"foreach문에서 나오는값 :{arrNames[1]}");
                System.Console.WriteLine($"foreach문에서 나오는값 :{arrNames[2]}");
                break;
 
            }
            
            while (true)
            {
                Console.WriteLine($"while문에서 나오는값 : {arrNames[0]}");
                Console.WriteLine($"while문에서 나오는값 : {arrNames[1]}");
                Console.WriteLine($"while문에서 나오는값 : {arrNames[2]}");
                break;
            }
 
 
            //배열의 길이 파악할때 사용
 
 
 
        }
 
        public Unit(string v)
        {
            this.v = v;
        }
    }
}
 
cs

 


728x90
반응형

'개임개발 > 수업내용' 카테고리의 다른 글

0322 프로그래밍  (0) 2019.03.22
: