指定した文字列をコンソールアプリケーションケーションウィンドウに打ち込んで表示されるもの、キーが押されたときに表示されるものの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;
}
}
}
}