본문 바로가기
프로그래머/코딩(C#)

_28_array_2

by FourthWay 2023. 5. 4.
728x90
반응형

C# , 배열

 

using System;

namespace _28_array
{
 internal class Program
 {
  static void Main(string[] args)
  {
   string[] names = {"홍길동", "임꺽정", "장길산", "일지매", "차돌바위"};
   ViewName(names);
  }
  
  static void ViewName(string[] args)
  {
   for(int i = 0, i < args.Length; i++)
   	  Console.WriteLine(args[i]);
  }
 }
}

string[] names = {"홍길동", "임꺽정", "장길산", "일지매", "차돌바위"}; 를 통해 배열을 할 단어들을 나열한다.

ViewName(names); 는 나열된 단어들을 가리킨다.

 

for(int i=0;i<args.Length;i++)
                Console.WriteLine(args[i]);

 

for문을 통해 i는 0번째부터 Length 배열의 길이(개수) 만큼 나열하고 i++ 하나씩 늘어난다.

Console.WriteLine 하나 나열하고 다음 라인에 나열해서 세로로 출력하도록 해준다.

 

728x90
반응형

'프로그래머 > 코딩(C#)' 카테고리의 다른 글

C#_Class[Question]  (1) 2023.05.04
_27_array_1  (1) 2023.05.02
_26_array  (0) 2023.05.02
_25_function_question  (0) 2023.05.01
_24_function  (1) 2023.04.28