본문 바로가기

분류 전체보기36

2024 - 12- 18 using System;using System.Collections.Generic;using System.Runtime.InteropServices;namespace ConsoleApp2{ class Buff { public string _buffName; public int _buffTime; public Buff(string buffName, int buffTime) { _buffName = buffName; _buffTime = buffTime; } } class BuffManager { LinkedList _buffs = new LinkedList(); .. 2024. 12. 18.
2024 - 12- 17 Gun이라는 클래스와 Projectile이라는 클래스를 만들겠습니다. 그리고 Projectile 클래스를 상속받는 Bullet클래스와 Grenade 클래스를 만듭니다.Grenade와 Bullet클래스에는 각각 필드로 int _damage 하나만 담아 둡니다.Gun 클래스에서 Bullet들을 담을 수 있는 List, Grenade들을 담을 수 있는 List, 총 두개의 리스트를 필드로 가지게 합니다.Gun의 생성자를 만들어서 해당 두 자료구조들을 뉴할당 시켜줍니다.Gun의 필드에 자료구조를 하나 더 추가합니다. 방금 만들어진 두 자료구조(Bullet을 담는 리스트, Grenade를 담는 리스트) 를 value값으로 관리할 수 있는 딕셔너리를 만듭니다. 키값으로는 string을 사용합니다. 이를 구현하기 위.. 2024. 12. 17.
List(참조형의 특징) 입력받은 요소를 리스트에 저장하는 코드를 작성하게 되었는데 모든 요소들이 마지막에 추가한 요소들로 바뀌는 문제점이 발견되었습니다.   코드클래스class Item{ public string name;} 메인static void Main(string[] args){ // 리스트 생성 List items = new List(); // Item클래스 생성 Item item = new Item(); // 현재 반복 횟수를 나타내는 count int count = 1; while (true) { // items 리스트에 item 추가 Console.Write($"{count} 번째 요소를 입력해 주세요 : "); items.Ad.. 2024. 12. 17.
2024 - 12 -16 using System;using System.Collections.Generic;using System.ComponentModel;using System.Linq;using System.Security.Cryptography.X509Certificates;using System.Text;using System.Threading.Tasks;using System.Xml.Serialization;namespace ConsoleApp2{ class UsableItem { string _name; int _price; int _mount; public string Name { get { return _name; } .. 2024. 12. 16.
c# 문법 - class(클래스), 생성자, 프로퍼티 클래스란? 클래스는 객체 지향 프로그래밍(OOP)의 핵심 요소로, 프로그램에서 특정 유형의 객체를 정의해 주는 역할을 합니다. 클래스는 속성(데이터)와 메서드(동작)를 포함하여 객체의 상태와 행동을 설명합니다  클래스생성// Test 클래스 생성class Test{ // 멤버 변수 int a;}  클래스 호출 Test test = new Test();  참조형식 특징Test test = new Test();test.int = 22;// 출력 - 22Console.WriteLine(test.int)test = new Test();// 출력 - 0Console.WriteLine(test.int) 같은 클래스가 두번 만들어지면 처음에 만들어졌던 클래스의 주소를 날리고 마지막에 만들어진 클래스의 주소를 .. 2024. 12. 13.
2024 - 12 - 13 using System;using System.Collections.Generic;using System.Linq;using System.Text;using System.Threading.Tasks;namespace ConsoleApp2{ interface Ilnteractable { // public이 아니어도 외부에서 사용 가능? void Interact(); } abstract class NPC { int _x; int _y; string _name; } class EnforceNpc : NPC, Ilnteractable { public void Interact() { .. 2024. 12. 13.