프로그래밍

C# paiza 74 - 딕셔너리2

노마드선샤인 2020. 5. 22. 23:01
728x90

//////////

/////

// 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