현재 교육받고 있는 학원에서 강사님이 좋은 제도를 만드셔서,
복습도 할겸 만들어본 메서드반환 문제입니다.
카페에 업로드한 것과 동일합니다.
네임리스트 문자열 컬렉션 객체를 생성하고, 차례대로 "홍길동" "임꺽정" 문자열값을 저장합니다.
그리고 스왑메서드를 이용해 역순으로("임꺽정" "홍길동") 다시 값을 저장하여 반환받아 출력합니다.
-----------------------------------------------------------------------------------------------------------------------------------
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
|
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Runtime.CompilerServices;
using System.Text;
namespace Question_1
{
class App
{
List<string> nameList;
public App()
{
nameList = new List<string>();
nameList.Add("홍길동");
nameList.Add("임꺽정");
foreach (string element in nameList)
{
Console.WriteLine(element); //홍길동, 임꺽정
}
Console.WriteLine();
nameList = this.GetSwapName(nameList);
foreach (string element in nameList)
{
Console.WriteLine(element); //임꺽정, 홍길동
}
}
public List<string> GetSwapName(List<string> list)
{
List<string> swapNameList = new List<string>(list);
swapNameList[i] = list[inx--];
return swapNameList;
}
}
}
|
-----------------------------------------------------------------------------------------------------------------------------------
출력값
-----------------------------------------------------------------------------------------------------------------------------------

'C# > 복습' 카테고리의 다른 글
2020-04-25 업적시스템 복습 & 생각정리 1 (0) | 2020.04.25 |
---|---|
메서드반환 문제2 (0) | 2020.04.21 |
백준 알고리즘 단계별 문제-For문 출력값 (0) | 2020.04.05 |
백준 알고리즘 단계별 문제-For문 Source (0) | 2020.04.05 |
백준 알고리즘 단계별 문제 - 입출력과 사칙연산 출력값 (0) | 2020.04.05 |