Basic Info
Programming Language: C# (C Sharp)
Program Type: Console .Net Core 2.0 Application
IDE: Visual Studios Community 2017 v15.8.7
Program Info
Program Name: Calendar Counter
Basics of my Program: User types in a month and it tells them how many days are in that month. The user is free to type any known combination of month name/identity (e.g. March, march, mar, Mar, Mar., mar., 03, or 3).
My Programs Execution: The program asks the user for a month and they type it in. The program then checks what the user typed to a method named MonthDatabase() with a String Array. If it matches it will display the month they typed in with how many days it has.
Issue Info
Program Issue: My main issue is finding a way to check what the user inputted with what's in the String Array. I've tried switches and different if statements, but most give me an error (I won't be posting all of those). I also tried it using the dictionary and a list. Each produced their own errors. So I went back to using a string array and after many searches and trying different things that just didn't work. I even tried to google for what I was looking to accomplish (e.g. check user input with string array) to no avail. Currently, the error I get is:
Delegate to an instance method cannot have null 'this'.
Now being new to C# (and programming in general) I could only assume that it wants me to specify what to check in the string array to match it to the user input. I tried something like:
Console.Write("Enter a month?: ");
string userMonth = (Console.ReadLine());
if (userMonth == mData(1, 1)) //Compare user input to MonthDataBase
{
Console.WriteLine("You typed a word found in the datatbase.");
}
else
{
Console.WriteLine("You didn't type a word in the datatbase.");
}
AND
Console.Write("Enter a month?: ");
string userMonth = (Console.ReadLine());
if (userMonth == mData[1, 1]) //Compare user input to MonthDataBase
{
Console.WriteLine("You typed a word found in the datatbase.");
}
else
{
Console.WriteLine("You didn't type a word in the datatbase.");
}
Thinking it would look at the string in that position and match it, but clearly, I am wrong on that assumption. I even tried to Google to see if there was a way to just simply match what the user typed to the whole string array, but found nothing.
I have spent a week trying to figure this out and decided to come here to see if anyone can point me in the right direction. I like the idea of learning it so if possible no direct answers as "do this" and it will work. Maybe an example (different, but close to what I'm trying to do) or "read this" and it should help you.
The Code
using System;
using System.Collections.Generic;
using System.Linq;
namespace Calendar_Counter
{
class Program
{
public static string mData { get; private set; } //Use mData in any method.
static void Main(string[] args)
{
Header(); //Call Header Method & display
Menu(); //Call Menu Method & display
CCDatatbase(); //Call Calendar Counter Database Method, execute & display.
//Console.WriteLine("Hello World!");
ExitProgram(); //Call exit program, execute & display
}
static void Header()
{
Console.Clear(); //Clear console buffer & console window of display information
Console.Write("--------------------\n| Calendar Counter |\n--------------------\n"); //Display Header text
}
static void Menu()
{
//ADD menu options once basic program is working!!
Console.WriteLine(); //Space
Console.Write("MENU: //ADD menu options once basic program is working!!");
Console.WriteLine("\n"); //Double Space
}
static void CCDatatbase()
{
Console.Write("Enter a month?: ");
string userMonth = (Console.ReadLine());
if (userMonth.Any(mData.Contains)) //Compare user input to MonthDataBase
{
Console.WriteLine("You typed a word found in the datatbase.");
}
else
{
Console.WriteLine("You didn't type a word in the datatbase.");
}
}
public static string[,] MonthDataBase() //Month Database
{
//Check user input with Array List.
string[,] mData = new string[12, 8]
{
{ "January", "january", "Jan", "jan", "Jan.", "jan.", "1", "01" }, //If user types 1-8 display corisponding message in CCDatatbase()
{ "January", "january", "Feb", "feb", "Feb.", "feb.", "2", "02" },
{ "March", "march", "Mar", "mar", "Mar.", "mar.", "3", "03" },
{ "April", "april", "Apr", "apr", "Apr.", "apr.", "4", "04" },
{ "May", "may", "May", "may", "May", "may", "5", "05" },
{ "June", "june", "Jun", "jun", "Jun.", "jun.", "6", "06" },
{ "July", "july", "Jul", "jul", "Jul.", "jul.", "7", "07" },
{ "August", "august", "Aug", "aug", "Aug.", "aug.", "8", "08" },
{ "September", "september", "Sep", "sep", "Sep.", "sep.", "9", "09" },
{ "October", "october", "Oct", "oct", "Oct.", "oct.", "10", "10" },
{ "November", "november", "Nov", "nov", "Nov.", "nov.", "11", "11" },
{ "December", "december", "Dec", "dec", "Dec.", "dec.", "12", "12" }
};
return mData;
}
static void ExitProgram()
{
//REPLACE later with an actual exit option in menu!!
Console.Write("EXIT: //REPLACE later with an actual exit option in menu!!\n\n");
//Prevent Debugging test from closing.
Console.Write("Press any key to Exit...");
Console.ReadLine();
}
}
}


