영웅 클래스의 아이디에 값을 할당하는 세가지 방법. App 클래스 using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace Study09 { class App { //생성자 public App() { Console.WriteLine("App생성자 입니다."); //방법1 //맴버변수 id의 한정자는 private //객체를 초기화 //Hero hero = new Hero(100); //방법 2 //맴버변수 id 한정자는 public //Hero hero = new Hero(); //hero.id = 100; //방법 3 //Hero her..
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace Study08 { class Inventory { private int capacity; //최대 용량 private Item[] items; //아이템들을 관리 배열 int index; //생성자 public Inventory(int capacity) { this.capacity = capacity; //배열 초기화 this.items = new Item[this.capacity]; } public void AddItem(Item item) { for (int i = 0; i < ..
내가 짠 코드 using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace Study07 { class App { //생성자 public App() { //최대값 구하기 int[] arrs = { 20, 10, 35, 30, 7 }; for (int i =0; i test) { test = arrs[i]; Console.WriteLine(test); } } //출력 //35 } } 최소값 구하기 for문 밖으로 변수 출력시키기 using System; using System.Collections.Generic; using System.Linq..
내가한 방식 using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace Study07 { class App { //생성자 public App() { int[] numbers = { 1, 3, 1, 3, 2, 3, 1, 4, 4, 5 }; Console.WriteLine("배열에서 찾아서 세고 싶은 숫자를 입력하세요"); string inputnum = Console.ReadLine(); int input = Convert.ToInt32(inputnum); int count = 0; foreach (int num in numbers) { if..
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace Study07 { class App { //생성자 public App() { Console.WriteLine("App 생성자."); //길이가 5개인 배열을 생성하고 모든 요소의 값을 -1로 초기화하세요 //같은 타입의 연속된 데이터들을 그룹하하고 관리하기 위함 - 배열의 사용 목적 //점수를 관리하기위해 배열을 사용했을때 int[] scores = new int[5]; //int[] scores = { -1, -1, -1, -1, -1 };// new int[5]; //scores..
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace Study06 { class App { public App() { Console.WriteLine("App 생성자 입니다."); //배열 //연속된 같은 데이터를 관리할수 있는 공간 //배열 변수 정의 //타입[] 변수명 //정수형 테이터들을 저장하고 싶다면 int[] scores; //배열 인스턴스를 생성 //생성된 배열은 반드시 할당을 해주어야 한다. scores = new int[5]; //배열 초기화 //배열의 요소(변수) 인덱스 0~...배열의 용량 -1 //인덱스로 접근이..
app단 using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace Study06 { class App { public App() { Console.WriteLine("App 생성자 입니다."); Hero hero = new Hero(); Monster monster = new Monster(); Coin coin = monster.Die(); monster = null; hero.Get(coin); Console.WriteLine(monster); } } } 코인 using System; using System.Collections.Gen..