C# Program that checks on the status of the Capslock with each character insert 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 &amp; 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.");
            }
        }
    }
}
if true return true else return false antipattern

Unecessary if statements when dealing with booleans is a very common beginner pitfall.

    static bool CapsCheck()
    {
            // Check if Capslock is Active
        if (Console.CapsLock == true)
        {
            return true;
        }
        else
        {
            return false;
        }
    }


Is equivalent to:

   static bool CapsCheck()
   {
       return Console.CapsLock;
   }


As a further simplification, you may use Console.CapsLock directly and avoid this function.

Another boolean simplification is

            if (CapsCheck() == true)
            {
                CapsNotify(true);   
            }
            else
            {
                CapsNotify(false);
            }


To:

 CapsNotify( CapsCheck() );


Or:

CapsNotify( Console.CapsLock );


Ternary simplification

In CapsNotify it is unecessary to use a full if else, a ternary is enough and simpler:

 Console.Writeline("CapsLock is" + (caps ? "Active" : "Inactive"));