Yesterday I asked a question here about how a method writes to the console. Today, I wrote this quick little program that doesn’t work like i thought it would. The program in the link never has a call from the Main method to write anything to the console, and yet text will appear there. I tried to follow the same logic with the little snippet below and it doesn’t do anything. Why isn’t the program below writing the word “hello” to the console? EDIT: link here
using System;
class DaysInMonth
{
static void Main(string[] args)
{
int[] DaysInMonth = { 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 };
Console.Write("enter the number of the month: ");
int month = Convert.ToInt32(Console.ReadLine());
Console.WriteLine("that month has {0} days", DaysInMonth[month - 1]);
}
static void WriteIt(string s)
{
string str = "hello";
Console.WriteLine(str);
}
}
The linked program creates a timer which has an event handler which writes to the console. Every time the timer “ticks”, it will call
TimerHandler.The code you’ve posted in the question doesn’t have anything like that – nothing refers to
WriteItin any way, shape or form.