반응형 C#41 배열 연습문제 namespace CSharp1 { internal class Program { //가장 높은 값 static int GetHightestScore(int[] scores) { int maxValue = 0; for (int i = 0; i 2023. 7. 6. 배열 namespace CSharp1 { internal class Program { static void Main(string[] args) { //배열 //참조 타입 int[] scores = new int[] { 10,20,30,40,50 }; int[] scores2 = new int[5]; scores2 = scores; scores2[0] = 9999; // 0 1 2 3 4 /*scores[0] = 10; scores[1] = 20; scores[2] = 30; scores[3] = 40; scores[4] = 50;*/ for (int i = 0; i 2023. 7. 6. TextRPG(객체지향 버전) Creature using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace CSharp { public enum CreatureType { None, Player, Monster } class Creature { CreatureType type; protected int hp = 0; protected int attack = 0; protected Creature(CreatureType type) { this.type = type; } public void SetInfo(int hp, int attack) { this.hp = hp; thi.. 2023. 7. 6. 문자열 using static CSharp.Program; namespace CSharp { class Program { static void Main(string[] args) { string name = "Harry Potter"; //1.찾기 bool found = name.Contains("Harry");//true name.IndexOf('P');//6 //2. 변형 name += " Junior";//"Harry Potter Junior" string lowerName = name.ToLower();//"harry potter junior" string upperName = name.ToLower();//"HARRY POTTER JUNIOR" string newName = name.Replace('r.. 2023. 7. 5. 다형성 using static CSharp.Program; namespace CSharp { //다형성 class Player { protected int hp; protected int attack; public virtual void Move() { Console.WriteLine("Player 이동!"); } } class Knight : Player { public override void Move() { base.Move(); Console.WriteLine("Knight 이동!"); } } class Mage : Player { public int mp; public override void Move() { Console.WriteLine("Mage 이동!"); } } class Program { s.. 2023. 7. 5. 클래스 형식 변환 using static CSharp.Program; namespace CSharp { class Player { protected int hp; protected int attack; } class Knight : Player { } class Mage : Player { public int mp; } class Program { static void EnterGame(Player player) { Mage mage = (player as Mage); /* bool isMage = player is Mage;*/ //if(isMage) if (mage != null) { mage.mp = 1; } } static void Main(string[] args) { Knight knight = new Knig.. 2023. 7. 5. 이전 1 2 3 4 5 6 7 다음 반응형