-
03/24 Func연습카테고리 없음 2021. 3. 24. 12:59
Program.cs
using System; namespace Study07 { class Program { static void Main(string[] args) { Console.WriteLine("Main"); new App(); } } }
App.cs
using System; using System.Collections.Generic; using System.Linq; using System.Threading; namespace Study07 { public class Backpack { int id; public Backpack(int id) { this.id = id; } } public class Player { Backpack backpack; public void Init(Backpack backpack) { this.backpack = backpack; } } public class ItemData { public int id; public string name; public ItemData(int id, string name) { this.id = id; this.name = name; } } public class Item { public ItemData Data { get; set; } public Item(ItemData itemData) { Data = itemData; } } public class App { //생성자 public App() { Console.WriteLine("App"); Func<int, Backpack> createBackpack = (id) => { return new Backpack(id); }; var backpack = createBackpack(100); Console.WriteLine(backpack); Player player = new Player(); player.Init(backpack); ItemData data = new ItemData(100, "SCAR-L"); Item item = new Item(data); Func<Item, ItemData> lookItem = (itemArg) => { return itemArg.Data; }; ItemData itemData = lookItem(item); Console.WriteLine("아이템 ID : {0}, 아이템이름 : {1}",itemData.id, itemData.name); } } }