Notice
Recent Posts
Recent Comments
Link
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | 4 | 5 | 6 | 7 |
8 | 9 | 10 | 11 | 12 | 13 | 14 |
15 | 16 | 17 | 18 | 19 | 20 | 21 |
22 | 23 | 24 | 25 | 26 | 27 | 28 |
29 | 30 |
Tags
- 문제풀이
- W3Schools
- 오류
- Unity
- dynamic
- dfs
- 기초
- w3school
- UE5
- python
- Programming
- loop
- DP
- 프로그래밍
- github
- Tutorial
- guide
- Algorithm
- Unreal Engine 5
- Basic
- Class
- 파이썬
- Material
- String
- parameter
- C#
- 재귀
- 시작해요 언리얼 2022
- 백준
- c++
Archives
- Today
- Total
행복한 개구리
C# 21.03.17.수업내용 본문
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Study004
{
class App
{
//생성자
public App()
{
/*//string 배열 변수 선언
Item[] items;
//string 배열 인스턴스 및 변수에 할당
items = new Item[5];
//string 배열의 요소에 값 할당
Item item1 = new Item("무야호");
Item item2 = new Item("그만큼 신이 나신다는 거지");
Item item3 = new Item("예, 저희가 많이 보죠");
items[0] = item1;
items[1] = item2;
items[2] = item3;
//string 배열의 길이 출력
Console.WriteLine(items.Length);
//string 배열의 요소 값 출력 (index: 0 ~ n-1)
for (int i = 0; i < items.Length; i++)
{
Console.WriteLine("{0}인덱스", i);
}
//for문과 foreach문을 사용해 string 배열의 요소 출력
for (int i = 0; i < items.Length; i++)
{
if (items[i] == null)
{
Console.WriteLine("null");
}
else
{
Console.WriteLine("{0}", items[i].name);
}
}
foreach (Item name in items)
{
if (name == null)
{
Console.WriteLine("EMPTY");
}
else
{
Console.WriteLine(name.GetName());
}*/
Console.WriteLine("App이 실행됩니다.");
/*//List<string> 배열 변수 선언
List<string> items = new List<string>();
//List<string> 배열 인스턴스 및 변수에 할당
Item item1 = new Item("연필");
Item item2 = new Item("지우개");
Item item3 = new Item("공책");
//<string> 배열의 요소에 값 추가
items.Add(item1.name);
items.Add(item2.name);
items.Add(item3.name);
//List<string> 의 길이 출력
Console.WriteLine(items.Count);
int i = 0;
//List<string> 배열의 요소 값 출력 (index : 0 ~ n-1)
foreach (string item in items)
{
Console.WriteLine("{0}인덱스, {1}", i, items[i]);
i++;
}
//for문과 foreach문을 사용해 string 배열의 요소 출력
for (int a = 0; a < items.Count; a++)
{
Console.WriteLine("{0}인덱스, {1}", a, items[a]);
}*/
//Dictionary<int, string> 변수 선언
//ex)
//100, "장검"
//101, "단검"
//102, "활"
//Dictionary<int, string> 인스턴스 및 변수에 할당
Dictionary<int, string> items;
items = new Dictionary<int, string>();
//Dictionary<int, string> 요소에 값 할당 (키와 값)
items.Add(100, "장검");
items.Add(101, "단검");
items.Add(102, "활");
//Dictionary<int, string>의 요소의 수 출력
Console.WriteLine(items.Count);
//Dictionary<int, string>의 요소 값 출력 (키로 찾아서, 여기서는 ID)
foreach(KeyValuePair<int, string> item in items)
{
Console.WriteLine(item.Key);
}
//foreach문을 사용해 Dictionary<int, string>의 요소 값 출력
foreach(KeyValuePair<int, string> item in items)
{
Console.WriteLine(item.Value);
}
}
}
}
================================================
★ 출력 잘 안됨
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Study004
{
class App
{
//생성자
public App()
{
Item[] items;
items = new Item[5];
Item item1 = new Item(100, "장검");
Item item2 = new Item(101, "단검");
Item item3 = new Item(102, "활");
items[0] = item1;
items[1] = item2;
items[2] = item3;
Console.WriteLine(items.Length);
int i = 0;
foreach(Item item in items)
{
if(items[i] != null)
{
Console.WriteLine("{0} / {1}", item.Id, items[i].name);
i++;
}
}
}
}
}
================================================
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Study004
{
class App
{
//생성자
public App()
{
/*인터페이스
기능에 대한 정의
ㄴ클래스를 다중상속 가능
ㄴ구조체에 대해 상속할 때
보통 대문자i를 사용하고 그 뒤에 형용사를 사용한다.(이름을 형용사같이 만듬)
본문이 신기하게 생겼음.
ㄴvoid Interface(); 이런식으로.
인터페이스에 상속된 클래스는 반드시 bool Equals(T obj)가 포함되어야 한다.
인터페이스는 직접 인스턴스화할 수 없다.
클래스 또는 여러 인터페이스를 구현할 수 있다.
클래스는 기본클래스를 상속할 수 있으며
Virtual클래스는 부모클래스의 것을 자식클래스에서 재정의 하도록 허용하는데 사용된다.
*/
}
}
}
================================================
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Study004
{
class Lurker : ZergUnit, IBurrow
{
public Lurker()
{
}
public override void Attack()
{
Console.WriteLine("가시로 공격합니다.");
}
public void IBurrow()
{
Console.WriteLine("버로우합니다.");
}
}
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Study004
{
class Ultralisk : ZergUnit
{
public Ultralisk()
{
}
public override void Attack()
{
Console.WriteLine("뿔로 공격합니다.");
}
}
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Study004
{
class ZergUnit
{
public ZergUnit()
{
}
public virtual void Attack()
{
Console.WriteLine("Attack");
}
}
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Study004
{
class ZergUnit
{
public ZergUnit()
{
}
public virtual void Attack()
{
Console.WriteLine("Attack");
}
}
}
================================================
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Study004
{
class Zealot : ProtossUnit
{
public Zealot()
{
}
public override void Attack()
{
Console.WriteLine("양손으로 공격합니다");
}
public override void Move()
{
Console.WriteLine("질럿이 빠르게 움직입니다.");
}
}
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Study004
{
class DarkTemplar : ProtossUnit, BeInvisable
{
public DarkTemplar()
{
}
public void BeInvisable()
{
Console.WriteLine("다크템플러를 볼 수 없습니다.");
}
public override void Attack()
{
Console.WriteLine("강하게 벱니다.");
}
public override void Move()
{
Console.WriteLine("다크템플러가 은밀히 움직입니다.");
}
}
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Study004
{
class Observer : ProtossUnit, BeInvisable, IFly
{
public Observer()
{
}
public void BeInvisable()
{
Console.WriteLine("옵저버를 볼 수 없습니다.");
}
public void IFly()
{
Console.WriteLine("옵저버가 날아다닙니다.");
}
public override void Move()
{
Console.WriteLine("옵저버가 이동합니다.");
}
}
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Study004
{
interface IFly
{
void IFly();
}
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Study004
{
interface BeInvisable
{
void BeInvisable();
}
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Study004
{
class ProtossUnit
{
public ProtossUnit()
{
}
public virtual void Move()
{
Console.WriteLine("유닛이 움직입니다.");
}
public virtual void Attack()
{
Console.WriteLine("유닛이 공격합니다.");
}
}
}
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Study004
{
class App
{
//생성자
public App()
{
Zealot zealot = new Zealot();
DarkTemplar darkTemplar = new DarkTemplar();
Observer observer = new Observer();
darkTemplar.BeInvisable();
observer.BeInvisable();
observer.IFly();
darkTemplar.Move();
zealot.Move();
observer.Move();
darkTemplar.Attack();
zealot.Attack();
zealot.Move();
}
}
}
================================================
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Study004
{
class DoranRing : Item, MagicPowerStatus
{
public DoranRing()
{
}
public void MagicPowerStatus()
{
Console.WriteLine("주문력이 올라갑니다.");
}
public override void BuyItem()
{
Console.WriteLine("도란의 반지를 구입합니다.");
}
public override void EquipItem()
{
Console.WriteLine("도란의 반지를 장착합니다.");
}
}
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Study004
{
class DoranSword : Item, AttackPowerStatus
{
public DoranSword()
{
}
public void AttackPowerStatus()
{
Console.WriteLine("공격력이 올라갑니다.");
}
public override void BuyItem()
{
Console.WriteLine("450골드를 주고 도란의 검을 구입합니다.");
}
public override void EquipItem()
{
Console.WriteLine("도란의 검을 장착합니다.");
}
}
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Study004
{
class Item
{
public Item()
{
}
public virtual void BuyItem()
{
Console.WriteLine("아이템을 구입합니다.");
}
public virtual void EquipItem()
{
Console.WriteLine("아이템을 장착합니다.");
}
}
}
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Study004
{
class App
{
//생성자
public App()
{
DoranRing doranRing = new DoranRing();
DoranSword doranSword = new DoranSword();
doranRing.BuyItem();
doranRing.EquipItem();
doranRing.MagicPowerStatus();
doranSword.BuyItem();
doranSword.EquipItem();
doranSword.AttackPowerStatus();
}
}
}
================================================
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Study003
{
class Zergling : ZergUnit, IBurrow
{
public Zergling()
{
}
public void Burrow()
{
Console.WriteLine("저글링이 버로우합니다.");
}
public override void Move()
{
Console.WriteLine("저글링이 움직입니다.");
}
public override void Attack()
{
Console.WriteLine("저글링이 앞발로 공격합니다.");
}
}
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Study003
{
class ZergUnit
{
public ZergUnit()
{
}
public virtual void Move()
{
Console.WriteLine("유닛이 움직입니다.");
}
public virtual void Attack()
{
Console.WriteLine("유닛이 공격합니다.");
}
}
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Study003
{
class Lurker : ZergUnit, IBurrow, IEvolution
{
public Lurker()
{
}
public void Burrow()
{
Console.WriteLine("럴커가 버로우합니다.");
}
public void Evolution()
{
Console.WriteLine("럴커로 변태합니다.");
}
public override void Move()
{
Console.WriteLine("럴커가 움직입니다.");
}
public override void Attack()
{
Console.WriteLine("럴커가 가시로 공격합니다");
}
}
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Study003
{
class Hydralisk : ZergUnit, IBurrow, IEvolution
{
public Hydralisk()
{
}
public void Burrow()
{
Console.WriteLine("히드라가 버로우합니다.");
}
public void Evolution()
{
Console.WriteLine("히드라가 변태를 시작합니다.");
}
public override void Move()
{
Console.WriteLine("히드라가 움직입니다");
}
public override void Attack()
{
Console.WriteLine("히드라가 등뼈로 공격합니다.");
}
}
}
using System;
using System.Collections;
using System.Collections.Generic;
namespace Study003
{
class App
{
//생성자
public App()
{
Console.WriteLine("App 실행됨");
Zergling zergling = new Zergling();
Hydralisk hydralisk = new Hydralisk();
Lurker lurker = new Lurker();
hydralisk.Move();
hydralisk.Burrow();
hydralisk.Evolution();
lurker.Move();
zergling.Move();
lurker.Burrow();
lurker.Attack();
zergling.Attack();
zergling.Burrow();
}
}
}
================================================
속성
공용 데이터 멤버처럼 속성을 사용할 수 있지만
실제로 접근자라는 특수 메서드이다.
get과 set이라는 키워드를 이용하여 정의할 수 있다.
이러한 접근자는 각기 다른 액세스 수준을 가질 수 있다.
value키워드는 접근자가 할당하는 값을 정의하는데 사용된다.
속성은 읽기/쓰기, 읽기, 쓰기 로 나뉜다
쓰기전용은 주로 중요한 데이터에 대한 엑세스를 제한하는데 사용된다.(거의 없다)
================================================
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Study000
{
public class App
{
//생성자
public App()
{
Console.WriteLine("App");
//Stack<Item> 변수 선언
Stack<Item> items;
//Stack<Item> 인스턴스 생성후 변수 할당
items = new Stack<Item>();
//Item 객체 생성
Item item1 = new Item("무야호");
Item item2 = new Item("저희가 많이 보죠");
//Stack에 값 추가 Push
items.Push(item1);
items.Push(item2);
//Stack의 요소 출력 (foreach)
foreach(Item name in items)
{
Console.WriteLine("{0}", name.name);
}
Console.WriteLine("--------- pop ----------");
//Stack에서 값 꺼내오기 Pop (출력 : 아이템의 이름)
Item popName = items.Pop();
Console.WriteLine("{0}", popName.name);
//Stack의 요소의 수 출력
Console.WriteLine(items.Count);
Console.WriteLine("--------- peek ----------");
//Stack의 요소 보기 Peek (출력: 아이템 이름)
Item peekName = items.Peek();
Console.WriteLine("{0}", peekName.name);
}
}
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Study000
{
class Item
{
public string name;
public Item(string name)
{
this.name = name;
}
}
}
================================================
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Study000
{
public class App
{
//생성자
public App()
{
Console.WriteLine("App");
//Queue<Unit> 변수 선언
Queue<Unit> units;
//Queue 객체 생성하고 변수에 할당
units = new Queue<Unit>();
//Unit객체 생성
Unit unit1 = new Unit("무");
Unit unit2 = new Unit("야");
Unit unit3 = new Unit("호");
//Enqueue
units.Enqueue(unit1);
units.Enqueue(unit2);
units.Enqueue(unit3);
//요소 수 출력
Console.WriteLine(units.Count);
//요소 출력 (유닛의 이름)
foreach(Unit unitName in units)
{
Console.WriteLine("{0}", unitName.name);
}
Console.WriteLine("***** Dequeue *****");
//Dequeue
string deQueueName = units.Dequeue().name;
Console.WriteLine(deQueueName);
//요소 수 출력
Console.WriteLine(units.Count);
Console.WriteLine("***** Peek *****");
//보기 (유닛의 이름)
string peekName = units.Peek().name;
Console.WriteLine(peekName);
//요소 수 출력
Console.WriteLine(units.Count);
Console.WriteLine("===== MuYaHo =====");
Console.WriteLine("그만큼 신이 나셨다는거지.");
}
}
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Study000
{
class Unit
{
public string name;
public Unit(string name)
{
this.name = name;
}
}
}
'C# > 수업내용' 카테고리의 다른 글
C# 21.03.19.수업내용 (0) | 2021.03.19 |
---|---|
C# 21.03.18.수업내용 (0) | 2021.03.18 |
C#21.03.16.수업내용 (0) | 2021.03.16 |
C#21.03.15.수업내용 (0) | 2021.03.15 |
C# 21.03.12.수업내용 (0) | 2021.03.12 |