1. 입력받은 문자열 배열 출력하기
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
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Study_010
{
class App
{
public App()
{
string[] strFruit = new string[3];
{
Console.Write("좋아하는 과일을 입력해주세요. ");
strFruit[i] = Console.ReadLine();
}
foreach (string fruit in strFruit)
{
Console.WriteLine(fruit);
}
Console.WriteLine("를 좋아하시는군요");
}
}
}
|
1) 결과값
2. 입력받은 배열값 거꾸로 출력하기
1) App class
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
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Study_010
{
class App
{
public App()
{
Fruit[] arrFruits = new Fruit[3];
{
Console.Write("좋아하는 과일을 입력해주세요 ");
arrFruits[i] = new Fruit(Console.ReadLine());
}
Console.WriteLine();
foreach (Fruit fruit in arrFruits)
{
Console.WriteLine("{0}, {1}, {2}", index, arrFruits[index], arrFruits[index].name);
index--;
}
Console.WriteLine("\n를 좋아하시는군요");
}
}
}
|
2) Fruit class
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Study_010
{
class Fruit
{
public string name;
public Fruit(string name)
{
this.name = name;
}
}
}
|
3) 결과값
'C# > 수업내용' 카테고리의 다른 글
2020.04.16. 수업내용 - 1) 문자열 분할하고 배열객체에 할당하기, 2) 배열 객체를 다른 클래스에 전달하기 (0) | 2020.04.16 |
---|---|
2020.04.16. 수업내용 - 장바구니 (장바구니 클래스, 과일 클래스) (0) | 2020.04.16 |
2020.04.14. 수업내용 - Barracks, Unit, Academy 클래스 (0) | 2020.04.14 |
2020.04.13. 수업내용 - Barracks, Unit class(enum) (0) | 2020.04.13 |
2020.04.13. 수업내용 - SiegeTank 클래스(enum), Factory 클래스 (0) | 2020.04.13 |