In this article we will learn how to convert month number to a month name in C# Console Application with array and if statement.
C# Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 |
class Program { static void Main(string[] args) { int monthNumber; Console.Write("Enter Month Number (1 - 12): "); monthNumber = Convert.ToInt32(Console.ReadLine()); string[] monthName = { "January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December" }; if(monthNumber>0 && monthNumber<13) { Console.WriteLine(monthName[monthNumber-1]); } Console.ReadLine(); } } |
Output:
Online Editor: