-
2020-04-15 [인벤토리 구축]C#/과제 2020. 4. 15. 23:53123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166using System;using System.Collections.Generic;using System.Linq;using System.Text;namespace practice009{class APP{public APP(){Inventory inventory = new Inventory(5); // 새로운 인벤토리를 생성inventory.InsertItem(new Item("롱소드")); /// items[0]inventory.InsertItem(new Item("롱보우")); /// items[1]inventory.InsertItem(new Item("클레이모어")); /// items[2]Item axe = inventory.InsertItem(new Item("도끼")); /// items[3]inventory.InsertItem(new Item("너클")); /// items[4]inventory.Getitem(axe);inventory.PrintItemlist();}}}==================================================================================using System;using System.Collections.Generic;using System.Linq;using System.Text;namespace practice009{class Item{public string name;public string founditem;public string getitem;public Item(string name){this.name = name;//Console.WriteLine("{0} 생성", this.name);}}}=================================================================================using System;using System.Collections.Generic;using System.ComponentModel;using System.Linq;using System.Text;namespace practice009{class Inventory{public Item[] items;public int itemidx;public Inventory(int capacity){//아이템 배열 생성 필요items = new Item[capacity]; // 입력 값만큼 배열값 생성Console.WriteLine("인벤토리 생성 완료");}public Item InsertItem(Item item){items[itemidx++] = item;return item;}public void PrintItemlist(){//for (int i = 0; i < this.items.Length; i++)//{// Console.WriteLine(this.items[i].name);//}foreach (Item item in items){}}public Item FindItem(string name){Item founditem = null;foreach (Item item in items){{}else{}}return founditem;//for (int i = 0; i < items.Length; i++)//{// if (items[i].name == name)// {// Console.WriteLine("찾는것 : {0} , 인벤토리 안 : {1} 발견", items[i].name, name);// }// else if (items[i].name != name)// {// Console.WriteLine("찾는것 : {0} / 인벤토리 안 : {1} 발견못함", items[i].name, name);// }//}//Console.WriteLine("반환값 {0}" , Array.IndexOf(items, name, itemidx));//Console.WriteLine("indexOf 메소드: {0}", Array.IndexOf(reading, 12));// Console.WriteLine("반환값 {0}", Array.IndexOf(items, name));}public Item Getitem(Item item){{{items[i].name = "[ ]";}}return item;}//특정 배열 요소를 삭제한다면 null 이 되면 될거 같음// finditem에서 찾을걸 삭제하면 ? 특정값 삭제하면 될거같음// 우선 null 이 되면 0 1 2 3 4 중 뒤 값과 비교해서 null 이라면 교환 형식으로다가// 넣었던 아이템이 없어져야 함// 근데 null 되면 계쏙 출력 안됨// 널리퍼런스, 런에 엑세스 하려할떄 나는건데...// for 돌려서 null 뜨는걸 뒤로 밀기?}}http://colorscripter.com/info#e" target="_blank" style="color:#e5e5e5text-decoration:none">Colored by Color Scripter
* 특정 배열 값이 null이 되면 오류가 뜨면서 안되서 방법을 못찾겠음
이부분은 추후 확인시 댓글로 후술
'C# > 과제' 카테고리의 다른 글
객체지향 3요소 / 5 원칙 둘러보고 간단 서술 (0) 2020.04.23 2020-04-18/19 [1차원 배열 활용] (0) 2020.04.20 2020-04-14 (1) 2020.04.14 연습 [2020-04-12] (2) 2020.04.12 2020-04-10 [할것] _ 기본 폼 완성 (1) 2020.04.10