Skip to main content
added 223 characters in body
Source Link

Depending on your style and .net version you can change some of your methods to Expression bodied function members:

/// documentation
static double ObvodTrojuhelniku(double a, double b, double c) => a + b + c

/// documentation
static double ObvodSestiuhelniku(double d) => 6 * d

/// documentation
static double ObsahSestiuhelniku(double d) => ((3 * Math.Sqrt(3) * Math.Pow(d, 2))) / 2;

I really like those small function you are using, they are easily testable and follow SRP - they have only one function and one reasons to change - if at all.


You should add input validation - if a user inputs "QWER" and you int.Parse(..) it directly, it will crash. Similarly for double.Parse(...)

where you do int VolbaObrazce = int.Parse(Console.ReadLine()); and inside static double PrectiPromennou(string text).


Depending on your style and .net version you can change some of your methods to Expression bodied function members:

/// documentation
static double ObvodTrojuhelniku(double a, double b, double c) => a + b + c

/// documentation
static double ObvodSestiuhelniku(double d) => 6 * d

/// documentation
static double ObsahSestiuhelniku(double d) => ((3 * Math.Sqrt(3) * Math.Pow(d, 2))) / 2;

You should add input validation - if a user inputs "QWER" and you int.Parse(..) it directly, it will crash. Similarly for double.Parse(...)

where you do int VolbaObrazce = int.Parse(Console.ReadLine()); and inside static double PrectiPromennou(string text).


Depending on your style and .net version you can change some of your methods to Expression bodied function members:

/// documentation
static double ObvodTrojuhelniku(double a, double b, double c) => a + b + c

/// documentation
static double ObvodSestiuhelniku(double d) => 6 * d

/// documentation
static double ObsahSestiuhelniku(double d) => ((3 * Math.Sqrt(3) * Math.Pow(d, 2))) / 2;

Depending on your style and .net version you can change some of your methods to Expression bodied function members:

/// documentation
static double ObvodTrojuhelniku(double a, double b, double c) => a + b + c

/// documentation
static double ObvodSestiuhelniku(double d) => 6 * d

/// documentation
static double ObsahSestiuhelniku(double d) => ((3 * Math.Sqrt(3) * Math.Pow(d, 2))) / 2;

I really like those small function you are using, they are easily testable and follow SRP - they have only one function and one reasons to change - if at all.


You should add input validation - if a user inputs "QWER" and you int.Parse(..) it directly, it will crash. Similarly for double.Parse(...)

where you do int VolbaObrazce = int.Parse(Console.ReadLine()); and inside static double PrectiPromennou(string text).

added 538 characters in body
Source Link

Consider using something along the lines of (documentation omitted for brevity):

public static class InputHelper
{
    /// Get<summary>
    /// Ask unser for input until a valid double valueis fromparsed
    /// </summary>
    /// <param name="text">The text presented to the user, repeatbefore untilinputting.</param>
 valid   /// <returns>double</returns>
    public static double GetDouble(string text)
    {
        string p = null;
        while (true)
        {
            Console.WriteLine(text);
            try
            {
                p = Console.ReadLine();
                return double.Parse(p);
            }
            catch (Exception ex)
            {
                if (ex is FormatException)
                {
                    Console.WriteLine($"Invalid input: '{p}' - only numbers and 1 decimal divider allowed!");
                }
                else if (ex is OverflowException)
                {
                    Console.WriteLine($"Invalid input: '{p}' - is too big. Max: {double.MaxValue}");
                }
            }
        }
    }

    /// Get<summary>
 a int value from/// user,Ask repeatunser for input until a valid integer is parsed
    /// </summary>
    /// <param name="text">The text presented to the user before inputting.</param>
    /// <returns>integer</returns>
    public static int GetInt(string text)
    {
        string p = null;
        while (true)
        {
            Console.WriteLine(text);
            try
            {
                p = Console.ReadLine();
                return int.Parse(p);
            }
            catch (Exception ex)
            {
                if (ex is FormatException)
                {
                    Console.WriteLine($"Invalid input: '{p}' - only numbers allowed!");
                }
                else if (ex is OverflowException)
                {
                    Console.WriteLine($"Invalid input: '{p}' - is too big. Max: {int.MaxValue}");
                }
            }
        }
    }
}

Consider using something along the lines of (documentation omitted for brevity):

public static class InputHelper
{
// Get a double value from user, repeat until valid
public static double GetDouble(string text)
{
    string p = null;
    while (true)
    {
        Console.WriteLine(text);
        try
        {
            p = Console.ReadLine();
            return double.Parse(p);
        }
        catch (Exception ex)
        {
            if (ex is FormatException)
            {
                Console.WriteLine($"Invalid input: '{p}' - only numbers and 1 decimal divider allowed!");
            }
            else if (ex is OverflowException)
            {
                Console.WriteLine($"Invalid input: '{p}' - is too big. Max: {double.MaxValue}");
            }
        }
    }
}

// Get a int value from user, repeat until valid
public static int GetInt(string text)
{
    string p = null;
    while (true)
    {
        Console.WriteLine(text);
        try
        {
            p = Console.ReadLine();
            return int.Parse(p);
        }
        catch (Exception ex)
        {
            if (ex is FormatException)
            {
                Console.WriteLine($"Invalid input: '{p}' - only numbers allowed!");
            }
            else if (ex is OverflowException)
            {
                Console.WriteLine($"Invalid input: '{p}' - is too big. Max: {int.MaxValue}");
            }
        }
    }
}

Consider using something along the lines of:

public static class InputHelper
{
    /// <summary>
    /// Ask unser for input until a valid double is parsed
    /// </summary>
    /// <param name="text">The text presented to the user before inputting.</param>
    /// <returns>double</returns>
    public static double GetDouble(string text)
    {
        string p = null;
        while (true)
        {
            Console.WriteLine(text);
            try
            {
                p = Console.ReadLine();
                return double.Parse(p);
            }
            catch (Exception ex)
            {
                if (ex is FormatException)
                {
                    Console.WriteLine($"Invalid input: '{p}' - only numbers and 1 decimal divider allowed!");
                }
                else if (ex is OverflowException)
                {
                    Console.WriteLine($"Invalid input: '{p}' - is too big. Max: {double.MaxValue}");
                }
            }
        }
    }

    /// <summary>
    /// Ask unser for input until a valid integer is parsed
    /// </summary>
    /// <param name="text">The text presented to the user before inputting.</param>
    /// <returns>integer</returns>
    public static int GetInt(string text)
    {
        string p = null;
        while (true)
        {
            Console.WriteLine(text);
            try
            {
                p = Console.ReadLine();
                return int.Parse(p);
            }
            catch (Exception ex)
            {
                if (ex is FormatException)
                {
                    Console.WriteLine($"Invalid input: '{p}' - only numbers allowed!");
                }
                else if (ex is OverflowException)
                {
                    Console.WriteLine($"Invalid input: '{p}' - is too big. Max: {int.MaxValue}");
                }
            }
        }
    }
}
added 542 characters in body
Source Link

Depending on your style and .net version you can change some of your methods to Expression bodied function members:

/// documentation
static double ObvodTrojuhelniku(double a, double b, double c) => a + b + c

/// documentation
static double ObvodSestiuhelniku(double d) => 6 * d

/// documentation
static double ObsahSestiuhelniku(double d) => ((3 * Math.Sqrt(3) * Math.Pow(d, 2))) / 2;

If you know about templating, you can reduce the duplicate code (DRY) in your static helpers. I put them into an extra class to be used in other projects as well.

If you know about templating, you can reduce the duplicate code (DRY) in your static helpers. I put them into an extra class to be used in other projects as well.

Depending on your style and .net version you can change some of your methods to Expression bodied function members:

/// documentation
static double ObvodTrojuhelniku(double a, double b, double c) => a + b + c

/// documentation
static double ObvodSestiuhelniku(double d) => 6 * d

/// documentation
static double ObsahSestiuhelniku(double d) => ((3 * Math.Sqrt(3) * Math.Pow(d, 2))) / 2;

If you know about templating, you can reduce the duplicate code (DRY) in your static helpers. I put them into an extra class to be used in other projects as well.

added 38 characters in body
Source Link
Loading
Source Link
Loading