2uzhan.com
Advertisement
Now Place:2uzhan.com » C# Methods, "not all code paths return a value"

C# Methods, "not all code paths return a value"

Software Development @ November 14, 2013   Views:0

I'm having trouble with this bit of code that I'm working on. I get an error code in my parseit()method that says, "not all code paths return a value". Ideally I'm trying to call my method and parse my variables from my textbox to return true when they're valid, then I'm going to use my boolean CheckNums in the if statement shown at the bottom.

I've been trying every which way to change my code, but I get an error no matter what I do. I think I've provided the relevant code. I know others have asked this question, but no matter what I do I can't get it to work.

decimal ascore = 0;
decimal midScore = 0;
decimal finalscore = 0;
bool CheckNums;

parseit(out ascore, out midScore, out finalscore);

        private bool parseit(out decimal ascore, out decimal midScore, out decimal finalscore)
        {
            if (decimal.TryParse(assignmentBox.Text, out ascore) && (ascore <= 100) && (ascore >= 0))
            {
                if (decimal.TryParse(midtermBox.Text, out midScore) && (midScore <= 100) && (midScore >= 0))
                {
                    if (decimal.TryParse(finalBox.Text, out finalscore) && (finalscore < 100) && (finalscore >= 0))
                    {
                        CheckNums = true;
                        return true;
                    }
                    else
                    {
                        CheckNums = false;

                    }
                }
                else
                {
                    CheckNums = false;
                }
            }
            else
            {
                CheckNums = false;
            }
        }

if (CheckNums == true)
    {
    Switch();
    }
else
    {
    BadInput();
    }

--------------Solutions-------------

I see the return statement on line 16, but nowhere else. What happens if the test on line 10 fails -- what will the function return??

line 6 you should poot

bool

as well

No, he already defined it as bool on line 4. I agree with Ancient dragon, he should probably use if else if and put return for each of that if statement.

Window x:Class="HexagonWindow.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
        xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
        xmlns:local="clr-namespace:HexagonWindow"
        mc:Ignorable="d"
        Title="Hexa" Height="300" Width="300" WindowStyle="None"
        AllowsTransparency="True" Background="Transparent" MouseLeftButtonDown="Window_MouseLeftButtonDown">
    <Grid>
        <!--Points="100,0 200,0 300,100 300,200 200,300 100,300 0,200 0,100" use these points for octagon window--> ...

Before I get into the specific issues, I want to provide some other details:

  • Normally, I work on a live, paid server (even in dev); I realize that is ...

Hey there,

I am trying to create a register code. So basicly im making a quiz and every time a user starts up my program he/she needs to register (making ...

Tags:
© 2018 2uzhan.com Contact