728x90
SMALL

/////////////

//////////

예외처리: 실행시에 발생하는 문제에 대응

메리트: 프로그램을 안정하여 동작하게 하는 시스템의 품질을 높임.

에러 메시지도 읽어서 취할 수 있다.

기술한 소스 코드 > 컴파일러(실행 가능한 형식으로 변환) > 실행한다.(순차, 계산이나 처리를 진행한다)

컴파일 에러 à 의 실수, 문법의 틀림 등.

실행 에러 à 실행 시에 에러: 계산할 수 없다. 파일이 없다 등

예외처리 기능

Try: 미리 코드를 지정하여, 프로그램을 실행했을 때에 처리의 문제를 검출한다.

Catch: 문제를 검출할 때, 어떻게 대응할 지를 기술해 둔다.

Throw: 프로그램 실행 중에 예외가 발생한 것을 통지한다.

예외가 발생하는 예

0으로 나눴을 때, 수치 변환에서 숫자가 아닌 문자를 지정, 배열의 범위 외에 억세스, 파일이 없음.

//////////

////

// な例外理をしてみよう

using System;

 

class Lesson10

{

    public static void Main()

    {

 

Console.WriteLine("Hello World");

int number = 2;

//int number =0으로 하면 실행이 되지 않는다.

int answer = 100 / number;

Console.WriteLine(answer);

Console.WriteLine("Hello C#");

 

    }

}

 

///

/////////

 

 

///

///////

// な例外理をしてみよう

using System;

 

class Lesson10

{

    public static void Main()

    {

 

Console.WriteLine("Hello World");

try

{

int number = 0;

int answer = 100 / number;

Console.WriteLine(answer);

 

}

catch(Exception e)

//exception 오브젝트가 메시지로 출력한다.

{

Console.WriteLine(e.Message);

}

//예외처리

finally

{

Console.WriteLine("Hello C#");

}

    }

}

//////

728x90

'프로그래밍' 카테고리의 다른 글

C# 탭 컨트롤1  (0) 2020.09.09
C#에서 탭 컨트롤 넣기  (0) 2020.09.09
C# paiza 79 - RPG 아이템 일람 재현  (0) 2020.05.23
C# paiza 78 - 화상이미지 출력  (0) 2020.05.23
C# paiza 77 - 딕셔너리 루프  (0) 2020.05.23

설정

트랙백

댓글

728x90
SMALL

////

 

// RPGのアイテム一を再現しよう

using System;

using System.Collections.Generic;

 

class Lesson09

{

    public static void Main()

    {

        var itemImages = new Dictionary<string, string>();

        itemImages.Add("", "http://paiza.jp/learning/images/sword.png");

        itemImages.Add("", "http://paiza.jp/learning/images/shield.png");

        itemImages.Add("回復", "http://paiza.jp/learning/images/potion.png");

        itemImages.Add("クリスタル", "http://paiza.jp/learning/images/crystal.png");

 

        string[] items = {"回復", "", "", "回復", "クリスタル", "クリスタル" };

 

        // アイテム名とURLを出力する

     foreach(var item in items)

     {

         Console.WriteLine(item);

         Console.WriteLine(itemImages[item]);

        

     }

    

       

    }

}

/////////

 

/////

////

 

레슨9 종료

728x90

'프로그래밍' 카테고리의 다른 글

C#에서 탭 컨트롤 넣기  (0) 2020.09.09
C# paiza 80 - 예외처리1  (0) 2020.05.23
C# paiza 78 - 화상이미지 출력  (0) 2020.05.23
C# paiza 77 - 딕셔너리 루프  (0) 2020.05.23
C# paiza 76 - 딕셔너리 활용  (0) 2020.05.23

설정

트랙백

댓글

728x90
SMALL

////

// RPGのアイテム一を再現しよう

using System;

using System.Collections.Generic;

 

class Lesson09

{

    public static void Main()

    {

        //화상용 딕셔너리 아이템도

        //

       

        var itemImages = new Dictionary<string, string>();

        itemImages.Add("", "http://paiza.jp/learning/images/sword.png");

        itemImages.Add("", "http://paiza.jp/learning/images/shield.png");

        itemImages.Add("回復", "http://paiza.jp/learning/images/potion.png");

        itemImages.Add("クリスタル", "http://paiza.jp/learning/images/crystal.png");

       

        string[] items = { "クリスタル", "", "", "回復", "回復", "回復" };

   foreach(var item in items)

   {

       Console.WriteLine("<img src='" + itemImages[item] + "'>");

       Console.WriteLine(item);

       Console.WriteLine("<br>");

   }

   //아이템의 이미지 출력

   //아이템 리스트가 출력

 

    }

}

////

 

 

//////////////

 

///////////////화상이미지 출력

//연습1

// RPGのアイテム一を再現しよう

using System;

using System.Collections.Generic;

 

class Lesson09

{

    public static void Main()

    {

        var itemImages = new Dictionary<string, string>();

        itemImages.Add("", "http://paiza.jp/learning/images/sword.png");

        itemImages.Add("", "http://paiza.jp/learning/images/shield.png");

        itemImages.Add("回復", "http://paiza.jp/learning/images/potion.png");

        itemImages.Add("クリスタル", "http://paiza.jp/learning/images/crystal.png");

 

        string[] items = { "", "", "回復", "クリスタル" };

 

        // 像のURLを出力する

        foreach (var item in items)

        {

            Console.WriteLine("<img src'" + itemImages[item] + "'>");

           // Console.WriteLine("<br>");

        }

    }

}

//////////////

 

728x90

'프로그래밍' 카테고리의 다른 글

C# paiza 80 - 예외처리1  (0) 2020.05.23
C# paiza 79 - RPG 아이템 일람 재현  (0) 2020.05.23
C# paiza 77 - 딕셔너리 루프  (0) 2020.05.23
C# paiza 76 - 딕셔너리 활용  (0) 2020.05.23
C# paiza 75 - 딕셔너리 조작  (0) 2020.05.22

설정

트랙백

댓글

728x90
SMALL

//////

// Dictionaryをルプで理しよう

using System;

using System.Collections.Generic;

 

class Lesson09

{

    public static void Main()

    {

        var enemyDictionary = new Dictionary<string,string>();

        enemyDictionary.Add("ザコ","スライム");

        enemyDictionary.Add("中ボス", "ドラゴン");

        enemyDictionary.Add("ラスボス", "魔王");

 

        Console.WriteLine(enemyDictionary["ザコ"]);

        foreach(var enemy in enemyDictionary)

        {

            Console.WriteLine(enemy.Key + "" + enemy.Value + "が現れた!");

        }

        //key value가 대입된다.

        //key는 자코 중간보소, 라스보스

        //value는 뒤에 있는 슬라임, 드래곤, 마왕이 대입된다.

    }

}

/////////

////

 

// Dictionaryをルプで理しよ

using System;

using System.Collections.Generic;

 

class Lesson09

{

    public static void Main()

    {

        var enemyDictionary = new Dictionary<string, string>();

        enemyDictionary.Add("ザコ", "スライム");

        enemyDictionary.Add("中ボス", "ドラゴン");

        enemyDictionary.Add("ラスボス", "魔王");

 

        // Dictionaryをルプで呼び出してください

foreach(var enemy in enemyDictionary)

{

        Console.WriteLine(enemy.Key + "" + enemy.Value + "が現れた");

}

    }

}

 

 

///////////////

////////

///

// Dictionaryをルプで理しよう

using System;

using System.Collections.Generic;

 

class Lesson09

{

    public static void Main()

    {

        var members = new Dictionary<string, string>();

        members.Add("", "つばめ");

        members.Add("六村", "リオ");

        members.Add("霧島", "京子");

 

        // Dictionaryをルプで呼び出してください

        foreach(KeyValuePair<string,string> enemy in members)

        {

           

            Console.WriteLine(enemy.Key + "さんの名前は" + enemy.Value + "です");

           

        }

       

       

    }

}

//////

/////////////////////

1. 아이템의 화상과 아이템의 이름을 표시한다.

2. 같은 아이템을 복수 표시한다.

3. 아이템의 정렬순을 관리한다.

4. 같은 아이템의 화상 파일은 하나를 공유한다.

딕셔너리와 배열을 組み合わせる必要があります。

아이템의 管理する 배열

나라비쥰에 번호, 아이템명에 아이템의 이름

화상용 딕셔너리 itemImages

Ex) 검이면 > sword.png 파일을 화상 파일로 읽어옴.

방패() > 방해 사진

Items[0] > 크리스탈 itemImages[items[0]] > 크리스탈 사진

이러한 내용을 루프로 처리한다.

/////////////////////////////

728x90

'프로그래밍' 카테고리의 다른 글

C# paiza 79 - RPG 아이템 일람 재현  (0) 2020.05.23
C# paiza 78 - 화상이미지 출력  (0) 2020.05.23
C# paiza 76 - 딕셔너리 활용  (0) 2020.05.23
C# paiza 75 - 딕셔너리 조작  (0) 2020.05.22
C# paiza 74 - 딕셔너리2  (0) 2020.05.22

설정

트랙백

댓글

728x90
SMALL

////////////////

/////

// Dictionaryから特定のキとバリュを削除してよう

using System;

using System.Collections.Generic;

 

class Lesson09

{

    public static void Main()

    {

        var enemyDictionary = new Dictionary<String, String>();

        enemyDictionary.Add("ザコ", "スライム");

        enemyDictionary.Add("中ボス", "ドラゴン");

        enemyDictionary.Add("ラスボス", "魔王");

 

        // 「ラスボス」キのペアを削除

         enemyDictionary.Remove("ラスボス");

        Console.WriteLine(enemyDictionary.Count);

    }

}

 

////////////

 

 

 

/////////

// Dictionaryをルプで理しよう

using System;

using System.Collections.Generic;

 

class Lesson09

{

    public static void Main()

    {

        var enemyDictionary = new Dictionary<string,string>();

        enemyDictionary.Add("ザコ","スライム");

        enemyDictionary.Add("中ボス", "ドラゴン");

        enemyDictionary.Add("ラスボス", "魔王");

 

        Console.WriteLine(enemyDictionary["ザコ"]);

        foreach(KeyValuePair<string,string> enemy in enemyDictionary)

        {

            Console.WriteLine(enemy.Key + "" + enemy.Value + "が現れた!");

        }

        //key value가 대입된다.

        //key는 자코 중간보소, 라스보스

        //value는 뒤에 있는 슬라임, 드래곤, 마왕이 대입된다.

    }

}

///////////////

 

/////

/////////////

728x90

'프로그래밍' 카테고리의 다른 글

C# paiza 78 - 화상이미지 출력  (0) 2020.05.23
C# paiza 77 - 딕셔너리 루프  (0) 2020.05.23
C# paiza 75 - 딕셔너리 조작  (0) 2020.05.22
C# paiza 74 - 딕셔너리2  (0) 2020.05.22
C# paiza 73 - 딕셔너리(Dictionary)1  (0) 2020.05.22

설정

트랙백

댓글

728x90
SMALL

//////////////

// Dictionaryの基本操作

using System;

using System.Collections.Generic;

 

class Lesson09

{

    public static void Main()

    {

               var enemyDictionary = new Dictionary<String, String>();

        enemyDictionary.Add("ザコ", "スライム");

        enemyDictionary.Add("中ボス", "ドラゴン");

        enemyDictionary.Add("ラスボス", "魔王");

Console.WriteLine(enemyDictionary["ザコ"]);

Console.WriteLine(enemyDictionary["中ボス"]);

Console.WriteLine(enemyDictionary["ラスボス"]);

 

Console.WriteLine(enemyDictionary.Count);

//count 정의 안해도 나온다.

enemyDictionary["中ボス"] = "レッサドラゴン";

Console.WriteLine(enemyDictionary["中ボス"]);

enemyDictionary.Remove("ラスボス");

Console.WriteLine(enemyDictionary.Count);

//라스보스 삭제

//라스보스는 존재하지 않는다

 

    }

}

////

 

/////////////////////

///////////

 

///////////

// バリュを更新しよう

using System;

using System.Collections.Generic;

 

class Lesson09

{

    public static void Main()

    {

        var enemyDictionary = new Dictionary<String, String>();

        enemyDictionary.Add("ザコ", "スライム");

        enemyDictionary.Add("中ボス", "ドラゴン");

        enemyDictionary.Add("ラスボス", "魔王");

 

        // 「中ボス」キのバリュ更してください

enemyDictionary["中ボス"] = "レッドドラゴン";

        Console.WriteLine(enemyDictionary["中ボス"]);

       

       

    }

}

 

728x90

'프로그래밍' 카테고리의 다른 글

C# paiza 77 - 딕셔너리 루프  (0) 2020.05.23
C# paiza 76 - 딕셔너리 활용  (0) 2020.05.23
C# paiza 74 - 딕셔너리2  (0) 2020.05.22
C# paiza 73 - 딕셔너리(Dictionary)1  (0) 2020.05.22
C# paiza 72 - 표준 라이브러리  (0) 2020.05.22

설정

트랙백

댓글

728x90
SMALL

//////////

/////

// Dictionary作成しよう

using System;

using System.Collections.Generic;

 

class Lesson09

{

    public static void Main()

    {

        // Dcitionaryを作り、要素を追加する

var enemyDictionary = new Dictionary<string, string>();

enemyDictionary.Add("ザコ","スライム");

  enemyDictionary.Add("中ボス","ドラゴン");

 enemyDictionary.Add("ラスボス","魔王");

 

        Console.WriteLine(enemyDictionary["ザコ"]);

        Console.WriteLine(enemyDictionary["中ボス"]);

        Console.WriteLine(enemyDictionary["ラスボス"]);

       

       

    }

}

//////////

//

 

////////////////

////////

// 変数にして値を取り出そう

using System;

using System.Collections.Generic;

 

class Lesson09

{

    public static void Main()

    {

        var enemyDictionary = new Dictionary<String, String>();

        enemyDictionary.Add("ザコ", "スライム");

        enemyDictionary.Add("中ボス", "ドラゴン");

        enemyDictionary.Add("ラスボス", "魔王");

 

        // 変数でスライムを呼び出す

var level = "ザコ";

        Console.WriteLine(enemyDictionary[level]);

    }

}

///////

 

////

// Dictionaryの基本操作

using System;

using System.Collections.Generic;

 

class Lesson09

{

    public static void Main()

    {

               var enemyDictionary = new Dictionary<String, String>();

        enemyDictionary.Add("ザコ", "スライム");

        enemyDictionary.Add("中ボス", "ドラゴン");

        enemyDictionary.Add("ラスボス", "魔王");

Console.WriteLine(enemyDictionary["ザコ"]);

Console.WriteLine(enemyDictionary["中ボス"]);

Console.WriteLine(enemyDictionary["ラスボス"]);

 

Console.WriteLine(enemyDictionary.Count);

//count 정의 안 해도 나온다.

 

    }

}

//////

728x90

'프로그래밍' 카테고리의 다른 글

C# paiza 76 - 딕셔너리 활용  (0) 2020.05.23
C# paiza 75 - 딕셔너리 조작  (0) 2020.05.22
C# paiza 73 - 딕셔너리(Dictionary)1  (0) 2020.05.22
C# paiza 72 - 표준 라이브러리  (0) 2020.05.22
C# paiza 71 - NameSpace  (0) 2020.05.19

설정

트랙백

댓글

728x90
SMALL

딕셔너리

//////////

데이터를 정리해서 키와 value로 관리할 수 있어서 편리하다. 다른 프로그래밍에서는 ??배열이라고 한다.

////

배열에 슬라임 드래곤 마왕을 넣으면, 데이터를 すこと가 가능.

딕셔너리는 dictionary[“ザコ”] =”슬라임

dictionary[“중간보스”] =”드래곤

dictionary[“라스보스”] =”마왕

이라는 데이터를 せる데이터

예를 들어, Enemies 데이터에 3개가 들어있다. 키로 데이터를 참조(Enemies[“ザコ]), 키를 변수로 구한다. 데이터의 개수

키를 변수로 구한다. Level = “중간보스” enemies[Level], 데이터 개수 = enemies.Count

데이터 추가, 변신, 삭제가 가능

딕셔너리의 용도 예: DBAPI와 야리토리하는 데이터의 처리 등

학생의 레코드를 Dictionary로 처리하기

//////////////////

// Dictionaryを作ろう

using System;

 

class Lesson09

{

    public static void Main()

    {

string[] enemyArray = {"スライム","モンスタ", "ドラゴン"};

Console.WriteLine(enemyArray[0]);

Console.WriteLine(enemyArray[1]);

Console.WriteLine(enemyArray[2]);

 

 

    }

}

////

///키로 처리

///////동물 딕셔너리

// Dictionaryを作ろう

using System;

using System.Collections.Generic;

 

class Lesson09

{

    public static void Main()

    {

string[] enemyArray = {"スライム","モンスタ", "ドラゴン"};

Console.WriteLine(enemyArray[0]);

Console.WriteLine(enemyArray[1]);

Console.WriteLine(enemyArray[2]);

Console.WriteLine();

 

 var enemyDictionary = new Dictionary<string, string>();

 enemyDictionary.Add("ザコ","スライム");

  enemyDictionary.Add("中ボス","ドラゴン");

 enemyDictionary.Add("ラスボス","魔王");

 Console.WriteLine(enemyDictionary["ザコ"]);

 Console.WriteLine(enemyDictionary["中ボス"]);

 Console.WriteLine(enemyDictionary["ラスボス"]);

 

    }

}

 

/////////////

 

///////

// Dictionaryを作ろう

using System;

using System.Collections.Generic;

 

class Lesson09

{

    public static void Main()

    {

string[] enemyArray = {"スライム","モンスタ", "ドラゴン"};

Console.WriteLine(enemyArray[0]);

Console.WriteLine(enemyArray[1]);

Console.WriteLine(enemyArray[2]);

Console.WriteLine();

 

 var enemyDictionary = new Dictionary<string, string>();

 enemyDictionary.Add("ザコ","スライム");

  enemyDictionary.Add("中ボス","ドラゴン");

 enemyDictionary.Add("ラスボス","魔王");

 Console.WriteLine(enemyDictionary["ザコ"]);

 Console.WriteLine(enemyDictionary["中ボス"]);

 Console.WriteLine(enemyDictionary["ラスボス"]);

 Console.WriteLine();

 var level = "ザコ";

 var opene = "ラスボス";

 Console.WriteLine(enemyDictionary[level]);

  Console.WriteLine(enemyDictionary[opene]);

 //ザコ에 있는 내용을 실행한다.

 //사전에 없는 단어를 입력하면 에러가 된다.

    }

}

 

/////////

 

/////

728x90

'프로그래밍' 카테고리의 다른 글

C# paiza 75 - 딕셔너리 조작  (0) 2020.05.22
C# paiza 74 - 딕셔너리2  (0) 2020.05.22
C# paiza 72 - 표준 라이브러리  (0) 2020.05.22
C# paiza 71 - NameSpace  (0) 2020.05.19
C# paiza 70 - 오버로드2  (0) 2020.05.19

설정

트랙백

댓글