I'm going to get another user and enter which month he wants and find the quarter.
Thought of writing the code inside a class as I need more training on how to use classes.
The program asks whose month it is and I can enter. But now when I type "January" only programs crash.
I assume that it should show which quarter "january" is in
namespace ConsoleApp1
{
internal class Program
{
static void Main(string[] args)
{
Console.WriteLine("Write a month");
var mc = new MyClass();
mc.month = Convert.ToString(Console.ReadLine());
}
public class MyClass
{
public string month;
public string Prop
{
get
{
return month;
}
set
{ if (Prop == "january")
{
Console.WriteLine("1.quarter");
}
}
}
}
}
}
CodePudding user response:
I tested your code and your program is not crashing. The program is actually completing and therefore the console is closing due to execution completing. So you can see what I mean try changing your code to this. You will see your code loop and the console will not close. It will also display what the user types in for mc.month
static void Main(string[] args)
{
while (true)
{
Console.WriteLine("Write a month");
var mc = new MyClass();
mc.month = Convert.ToString(Console.ReadLine());
Console.WriteLine(mc.month);
}
}
On a side note, not really how I would use a class. You might want to also rethink that. Don't normally see writelines in class.
CodePudding user response:
just check if value of property