Cách viết hàm if C# có thể bạn chưa từng viết
Cách 1
C# 2016
using System; using System.IO; using System.Collections.Generic; using System.Collections; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Runtime.Serialization.Formatters.Binary; namespace ConsoleApplication3 { class program { static void Main(string[] args) { Console.WriteLine("Chon 1 hoac 2"); string choose = Console.ReadLine(); if (choose == "1") { Console.WriteLine("Con meo"); Console.ReadLine(); } else if (choose == "2") { Console.WriteLine("Con cho"); Console.ReadLine(); } else { Console.WriteLine("Khong nam trong list chon"); Console.ReadLine(); } Console.ReadLine(); } } }
Cách 2
C# 2016
using System; using System.IO; using System.Collections.Generic; using System.Collections; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Runtime.Serialization.Formatters.Binary; namespace ConsoleApplication3 { class program { static void Main(string[] args) { Console.WriteLine("Chon 1 hoac 2"); string choose = Console.ReadLine(); string message = ""; if (choose == "1") { message = "con meo"; } else if (choose == "2") { message = "con cho"; } else { message = "khong nam trong list"; } Console.WriteLine(message); Console.ReadLine(); } } }
trong Java
Gởi Java 2016
using System; using System.IO; using System.Collections.Generic; using System.Collections; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Runtime.Serialization.Formatters.Binary; namespace ConsoleApplication3 { class program { static void Main(string[] args) { Console.WriteLine("Chon 1 hoac 2"); string choose = Console.ReadLine(); string message = ""; if (choose == "1") message = "con meo"; else if (choose == "2") message = "con cho"; else message = "khong nam trong list"; Console.WriteLine(message); Console.ReadLine(); } } }
0 nhận xét:
Post a Comment