473,387 Members | 1,687 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

how can i make a short codding of calendar using try catch?

Expand|Select|Wrap|Line Numbers
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Text;
  4. using System.Text.RegularExpressions;
  5. namespace ConsoleApp10
  6. {
  7.     class Program
  8.     {
  9.  
  10.         static void Main(string[] args)
  11.         {
  12.             int year = 0;
  13.             int month = 0;
  14.             DateTime targetMonth = DateTime.Now;
  15.             int[,] calendar = new int[6, 7];
  16.  
  17.             try
  18.             {
  19.  
  20.                 year = int.Parse(args[0]);
  21.                 month = int.Parse(args[1]);
  22.                 targetMonth = new DateTime(year, month, 1);
  23.  
  24.  
  25.             }
  26.             catch
  27.             {
  28.                 Console.WriteLine("引数が不正です。");
  29.                 return;
  30.             }
  31.  
  32.             Console.WriteLine("該当月のカレンダーを出力します");
  33.             Console.WriteLine(string.Format("{0:yyyy年MM月}", targetMonth));
  34.             Console.WriteLine("日 月 火 水 木 金 土");
  35.             int days = DateTime.DaysInMonth(year, month);
  36.             int currentDay = 1;
  37.  
  38.             for (int i = 0; i < calendar.GetLength(0); i++)
  39.             {
  40.                 for (int j = 0; j < calendar.GetLength(1) && currentDay <= days; j++)
  41.                 {
  42.                     if (i == 0 && month > j)
  43.                     {
  44.                         calendar[i, j] = 0;
  45.                     }
  46.                     else
  47.                     {
  48.                         calendar[i, j] = currentDay;
  49.                         currentDay++;
  50.                     }
  51.                 }
  52.             }
  53.  
  54.  
  55.             for (int i = 0; i < calendar.GetLength(0); i++)
  56.             {
  57.                 for (int j = 0; j < calendar.GetLength(1); j++)
  58.                 {
  59.                     if (calendar[i, j] > 0)
  60.                     {
  61.                         if (calendar[i, j] < 10)
  62.                         {
  63.                             Console.Write(" " + calendar[i, j] + " ");
  64.                         }
  65.                         else
  66.                         {
  67.                             Console.Write(calendar[i, j] + " ");
  68.                         }
  69.                     }
  70.                     else
  71.                     {
  72.                         Console.Write("   ");
  73.                     }
  74.                 }
  75.                 Console.WriteLine("");
  76.             }
  77.  
  78.  
  79.         }
  80.     }
  81. }
  82.  
  83.  
Attached Images
File Type: png image.PNG (35.0 KB, 94 views)
Dec 17 '19 #1
0 1483

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: kgatchell2001 | last post by:
Hi, I am a beginner working on a database to manage clients, payroll, station assignments, etc. I have created a query which calculates age based on subtracting the date of birth from the current...
4
by: Abhishek Srivastava | last post by:
Hello All, I have seen code snippets like try { ..... } catch {
24
by: Chameleon | last post by:
Is there a possibility to create memory leak, the code below if I run the line: --------------------------------------------------------- MyClass cl = new MyClass();...
2
cassbiz
by: cassbiz | last post by:
I am using strtotime and I have read up on some examples and am getting the wrong output, it jumps by several days instead of one day at a time. Ultimately what I am trying to accomplish is to set...
1
by: CoachBarkerOJPW | last post by:
We are expanding an application we wrote last semester for a course at school. It is written in VB.net with an Access data base.We were wondering if is possible to use Data Grid View to create a...
2
by: David C | last post by:
Using .Net 2 and VS2005. I have a calendar control in a TD cell of a table in the edit template of a FormView. I have the calendar .Visible property set to false but the control still uses up all...
2
by: haringmunti | last post by:
hi, im new to vb.net and i think it is very interesting. im taking a course on it right now and sadly, the one giving the lecture is not doing a good job. anyway, my question is how do i make a...
1
by: swethak | last post by:
hi, i have a code to disply the calendar and add events to that. It works fine.But my requirement is to i have to disply a weekly and daily calendar.Any body plz suggest that what modifications i...
0
by: satya uppe | last post by:
Hi vidi, In your code you have build the calendar content using string buffer. I want to build calendar using ical4j API itself. For example Calendar calendar = new Calendar();
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.