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
28
29
30
31
32
33
34
35
36
37
38
39
40
41
|
using System;
using System.Collections;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using static System.Console;
using System.IO;
namespace Practice2
{
class Car
{
public int Cost { get; set; }
public int MaxSpeed { get; set; }
}
class MainApp
{
static void Main(string[] args)
{
Car[] cars =
{
new Car() {Cost=56,MaxSpeed=120 },
new Car() {Cost=70,MaxSpeed=150 },
new Car() {Cost=45,MaxSpeed=180 },
new Car() {Cost=32,MaxSpeed=200 },
new Car() {Cost=82,MaxSpeed=280 }
};
var selected = from car in cars
where car.Cost >= 50 &&
car.MaxSpeed >= 150
select new
{
cost = car.Cost,
maxspeed = car.MaxSpeed
};
foreach(var car in selected)
WriteLine("Cost = {0}, MaxSpeed = {1}", car.cost, car.maxspeed);
}
}
}
http://colorscripter.com/info#e" target="_blank" style="color:#4f4f4ftext-decoration:none">Colored by Color Scripter
|
http://colorscripter.com/info#e" target="_blank" style="text-decoration:none;color:white">cs |
2번 문제
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
|
using System;
using System.Collections;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using static System.Console;
using System.IO;
namespace Practice2
{
class Car
{
public int Cost { get; set; }
public int MaxSpeed { get; set; }
}
class MainApp
{
static void Main(string[] args)
{
Car[] cars =
{
new Car() {Cost=56,MaxSpeed=120 },
new Car() {Cost=70,MaxSpeed=150 },
new Car() {Cost=45,MaxSpeed=180 },
new Car() {Cost=32,MaxSpeed=200 },
new Car() {Cost=82,MaxSpeed=280 }
};
var selected = from car in cars
where car.Cost < 60
orderby car.Cost
select new
{
cost = car.Cost,
maxspeed = car.MaxSpeed
};
foreach (var car in selected)
WriteLine("Cost = {0}, MaxSpeed = {1}", car.cost, car.maxspeed);
}
}
}
http://colorscripter.com/info#e" target="_blank" style="color:#4f4f4ftext-decoration:none">Colored by Color Scripter
|
http://colorscripter.com/info#e" target="_blank" style="text-decoration:none;color:white">cs |
'Programming Language > 이것이 C# 연습문제 풀이' 카테고리의 다른 글
이것이 C# 16장 연습문제 풀이 (1) | 2019.12.20 |
---|---|
이것이 C# 14장 연습문제 풀이 (0) | 2019.12.20 |
이것이 C# 13장 연습문제 풀이 (0) | 2019.12.19 |
이것이 C# 12장 연습문제 풀이 (2) | 2019.05.15 |
이것이 C# 11장 연습문제 풀이 (0) | 2019.05.13 |