HiveBrain v1.2.0
Get Started
← Back to all entries
patterncsharpMinor

Console-based menu system

Submitted by: @import:stackexchange-codereview··
0
Viewed 0 times
consolesystemmenubased

Problem

Recently I started learning programming and I created this program. I've added something to it with every new lesson.

How is my code-writing? Do I make mistakes I shouldn't make?

The program itself

```
static void Main()
{
{
Console.WriteLine("Select language:\n");
Console.WriteLine("1. Bulgarian");
Console.WriteLine("2. English\n");
Console.Write("Number: ");
byte language = byte.Parse(Console.ReadLine());
//....
//Skipped to
//English

if (language == 2)
{
Console.Clear();
string restart = "Press any key to exit the program...";
Console.CursorVisible = true;
string chislo = "Please press the number that corresponds to the function:";
Console.WriteLine(chislo);
Console.WriteLine();
Console.WriteLine("1. Balance calculator");
Console.WriteLine("2. Calculating numbers");
Console.WriteLine("3. Comparing numbers");
Console.WriteLine("4. Time and Date");
Console.WriteLine("5. Calculation of the number of words and characters from a text/sentence \n");
Console.WriteLine("Settings:\n");
Console.WriteLine("6. Change the color of the console \n");
Console.Write("Number: ");
string chisloFunkciq = Console.ReadLine();
int chisloFunkciqParse;
if (int.TryParse(chisloFunkciq, out chisloFunkciqParse))
{
Console.Clear();

//Funkciq Saldo

if (chisloFunkciqParse == 1)
{
Console.WriteLine("You chose \"Balance calculator\" \n");
bool check = true;
while (check == true)
{
Console.Write("Enter the opening balance: ");
string nachalnoSaldo = Console.ReadLine();

Solution

One thing that I don't like about your code is the recursive call to Main(); inside of Main().

I don't think this is healthy, if the application is run for an extended period of time, or run over and over again you will have issues with memory management.

What happens is the first time through you start a thread and then never fully release the thread before you call another thread, so you lock the memory that was being used and it isn't deallocated/destroyed.

Instead of doing this, you should wrap the entire application in a single while loop based on a Boolean variable that you can change to false when you want to exit the program.

I am not completely sure what is going on here.

static void Main()
    {
        {
            Console.WriteLine("Select language:\n");
            Console.WriteLine("1. Bulgarian");
            Console.WriteLine("2. English\n");
            Console.Write("Number: ");
            byte language = byte.Parse(Console.ReadLine());
        //....


  • Why is there two starting Brackets?



  • Why do you indent the first bracket?



  • is this preference in the coding?



  • personally this would confuse me a little bit



I would write it like this

static void Main()
{
    Console.WriteLine("Select language:\n");
    Console.WriteLine("1. Bulgarian");
    Console.WriteLine("2. English\n");
    Console.Write("Number: ");
    byte language = byte.Parse(Console.ReadLine());
        //....


And with that, I think that you are missing a bracket at the end if you intentionally doubled up the bracket (I think doubling up the brackets might irritate the compiler; I have never tried so I don't know for sure).

Other than that, the syntax looks good and isn't missing any semi-colons, and doesn't have any other weird indentations.

Code Snippets

static void Main()
    {
        {
            Console.WriteLine("Select language:\n");
            Console.WriteLine("1. Bulgarian");
            Console.WriteLine("2. English\n");
            Console.Write("Number: ");
            byte language = byte.Parse(Console.ReadLine());
        //....
static void Main()
{
    Console.WriteLine("Select language:\n");
    Console.WriteLine("1. Bulgarian");
    Console.WriteLine("2. English\n");
    Console.Write("Number: ");
    byte language = byte.Parse(Console.ReadLine());
        //....

Context

StackExchange Code Review Q#41680, answer score: 7

Revisions (0)

No revisions yet.