LoginSignup
1
0

More than 5 years have passed since last update.

条件によって異なる文字列を表示させるプログラム(自己記録用

Last updated at Posted at 2016-12-17

指定した文字列をコンソールアプリケーションケーションウィンドウに打ち込んで表示されるもの、キーが押されたときに表示されるものの2つ。このコードではEnterキーだが他のキーでも問題はない。

using System;

namespace A
{
    class Program
    {
        static void Main(string[] args)
        {
            string s = "hello";//条件となる文字列を指定する
            s = Console.ReadLine();
            if (s == "hello")
                Console.WriteLine("Oh!hello!");//文字列がウィンドウに入力されたら表記する
            string t = "nice to meet you";//string sに同じ
       t= Console.ReadLine();
            if (t == "nice to meet you")
                Console.WriteLine("nice to meet you too");
            ConsoleKeyInfo Start = Console.ReadKey();//キー情報の取得
            switch (Start.Key)//エンターキーが押されたときの動作
            {
                case ConsoleKey.Enter:
                    Console.WriteLine("Communication was not found");
                    break;
            }
        }
    }
}
1
0
0

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
1
0