3
2

More than 3 years have passed since last update.

連想配列を説明する

Last updated at Posted at 2020-05-15

じゃあまずC#で書く。

ex.cs
using System;
using System.Collections.Generic;
public class Ex{
    public static void Main(){
        var jcpmusicdotcom = new Dictionary<string,string>();
        jcpmusicdotcom["東方ロストワード"] = "ロストワードクロニカル";
        jcpmusicdotcom["俺はボーマンダ"] = "レプリカの恋";
        jcpmusicdotcom["ほのぼの神社"] = "SHAMAN QUEEN";
        foreach(var music in jcpmusicdotcom){
            Console.WriteLine($"{music.Value}は、{music.Key}を連想する音楽です。");
        }
    }
}

次にPythonで書いてみる。

ex.py
class Ex:
    def main():
        jcpmusicdotcom = {}
        jcpmusicdotcom["東方ロストワード"] = "ロストワードクロニカル"
        jcpmusicdotcom["俺はボーマンダ"] = "レプリカの恋"
        jcpmusicdotcom["ほのぼの神社"] = "SHAMAN QUEEN"
        for musickey in jcpmusicdotcom:
            print(f"{jcpmusicdotcom[musickey]}は、{musickey}を連想する音楽です。")

if __name__ == "__main__":
    Ex.main()

やはりどちらもC言語の影響があるので大して書き方が変わらないですね。私は、結構C#とかPythonとかの「汚い書き方ができないスタイル」が好きなのですが、皆さんはどうですか?コメントよろしくお願いします。

3
2
3

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
3
2