The following is my first successful running C# program.
The lessons that I personally learnt through this include:
- The value of asking for help after having tried several times
- The advantages of being adaptable about one's methods of reaching an end
- The (a?) proper placement of functions in relation to a main program
- How to pass information into and out of such functions
- How to use a loop to leverage code (doing the same stuff over and over)
- How to collect character input from the User & I'm sure there's more...
In any case this code appears to work. I know that it doesn't hold a candle to much of the stuff you guys put up but on the bright side its short and kind of readable (both aims of mine).
Could some much brighter spark than me kindly shine a light on the stuff that could have been done better (or simply provide some advice or suggested direction)? :c)
using System;
namespace CapsChecker
{
class Program
{
static void Main(string[] args)
{
//Set up an infinite loop for program to run within
while (true)
{
//Collection of user input
Console.Write("Press a key: ");
char input = (Console.ReadKey().KeyChar);
//Check if Capslock is on when key entered. Combined with
//the shift button this can result in CapsCheck returning
//true even if key entered is lower case.
if (CapsCheck() == true)
{
CapsNotify(true);
}
else
{
CapsNotify(false);
}
Console.WriteLine();
switch (input) //Abandoned '.Key' enum
{
case 'Q':
{ break; }
default:
{ continue; }
}
break; //Afterthoght as it wasn't breaking on capital Q.
}
Console.WriteLine("Program ending. Press a key.");
Console.ReadKey();
}
static bool CapsCheck()
{
// Check if Capslock is Active
if (Console.CapsLock == true)
{
return true;
}
else
{
return false;
}
}
static void CapsNotify(bool caps)
{
// Notify whether Capslock is Active
if (caps == true)
{
Console.WriteLine(" Capslock is Active.");
}
else
{
Console.WriteLine(" Capslock is Inactive.");
}
}
}
}