473,441 Members | 1,331 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,441 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 1485

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();
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...

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.