Notice
Recent Posts
Recent Comments
Link
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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 |
Tags
- 시작해요 언리얼 2022
- github
- guide
- Unity
- DP
- w3school
- W3Schools
- 백준
- 문제풀이
- 오류
- dynamic
- Material
- C#
- 프로그래밍
- 파이썬
- 재귀
- Class
- loop
- python
- parameter
- Unreal Engine 5
- Basic
- 기초
- String
- Tutorial
- Algorithm
- Programming
- UE5
- c++
- dfs
Archives
- Today
- Total
행복한 개구리
C# 21.03.22.과제 11 본문
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
namespace Homework1234
{
public class App
{
public App()
{
Console.WriteLine("App");
SCV scv = new SCV();
scv.mineComplete = this.MineComplete;
scv.MineMineral();
}
private void MineComplete()
{
Console.WriteLine("미네랄 +8");
}
}
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
namespace Homework1234
{
class SCV
{
public Action mineComplete;
public SCV()
{
}
public void MineMineral()
{
Console.WriteLine("SCV가 미네랄을 캡니다.");
Thread.Sleep(2000);
this.mineComplete();
}
}
}

================================================
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
namespace Homework1234
{
public class App
{
public App()
{
BookDB bookDB = new BookDB();
bookDB.AddBook("무소유", 12000, true);
bookDB.AddBook("이것이 C#이다", 17500, true);
bookDB.AddBook("반지의 제왕", 14000, false);
bookDB.ProcessBooks(true, PrintTitle);
PriceTotaller totaller = new PriceTotaller();
bookDB.ProcessBooks(true, totaller.AddBookToTotal);
Console.WriteLine("{0}, {1}", totaller.CountBooks, totaller.PriceBooks);
bookDB.FindBookByName("해리포터", FoundBook);
}
public void FoundBook(string title)
{
if (string.IsNullOrEmpty(title))
{
Console.WriteLine("책을 찾을 수 없습니다.");
}
else
{
Console.WriteLine("{0}을 찾았습니다.", title);
}
}
public void PrintTitle(Book book)
{
Console.WriteLine("{0}, {1}, {2}", book.title, book.price, book.paperback);
}
}
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Homework1234
{
class PriceTotaller
{
public int CountBooks
{
get; private set;
}
public int PriceBooks
{
get; private set;
}
public PriceTotaller()
{
}
public void AddBookToTotal(Book book)
{
this.CountBooks += 1;
this.PriceBooks += book.price;
}
}
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Homework1234
{
public struct Book
{
public string title;
public int price;
public bool paperback;
public Book(string title, int price, bool paperback)
{
this.title = title;
this.price = price;
this.paperback = paperback;
}
}
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Homework1234
{
public delegate void ProcessBookCallback(Book book);
public class BookDB
{
private List<Book> list;
public BookDB()
{
this.list = new List<Book>();
}
public void AddBook(string title, int price, bool paperback)
{
Book book = new Book(title, price, paperback);
this.list.Add(book);
}
public void ProcessBooks(bool paperback, ProcessBookCallback callback)
{
foreach(Book book in list)
{
if(book.paperback == paperback)
{
callback(book);
}
}
}
public void FindBookByName(string title, Action<string> callback)
{
foreach(Book book in list)
{
if(book.title == title)
{
callback(book.title);
return;
}
}
callback(string.Empty);
}
}
}
어려워서 한번 더 함
'C# > 수업과제' 카테고리의 다른 글
C# 21.03.24.과제12 (0) | 2021.03.24 |
---|---|
C# 21.03.19 ~ 21.과제10 (0) | 2021.03.20 |
C# 21.03.18.과제 (0) | 2021.03.18 |
C# 21.03.17.과제 8 (0) | 2021.03.17 |
C# 21.03.16.과제 7 (0) | 2021.03.16 |