C# ‘Program.ceackforablock(bool[,])’: not all code paths return a value

**Question:any one know why i’m geting this? I get a error that says ‘Program.ceackforablock(bool[,])’: not all code paths return a value

csharp**


Repl link:https://replit.com/@Josephyc/ticktactoe

 public bool ceackforablock(bool[,] inputaray)
    {
        bool isblocked = false;
        bool[,] isblockedaray = { { false, false, false }, { false, false, false }, { false, false, false } };
        int x = -1;
        int y = -1;
        int isthisthefirstone = 0;
        if (isthisthefirstone == 0)
        {
            foreach (bool input in inputaray)
            {
                bool isyesinputturn = false;
                if (x == 3)
                {
                    y++;
                    x = -1;
                }
                if (x > 3)
                {
                    x++;
                }
                if (input)
                {
                    isblockedaray[x, y] = true;
                    return isyesinputturn = true;
                }
                if (!(input) && (isyesinputturn = false))
                {
                    isblockedaray[x, y] = false;
                    return isyesinputturn = false;
                }
                isyesinputturn = false;
            }
        }
        if (isthisthefirstone > 0)
        {
            foreach (bool input2 in inputaray)
            {
                if (x == 3)
                {
                    y++;
                    x = -1;
                }
                if (x > 3)
                {
                    x++;
                }
                if (input2 == true && isblockedaray[x, y] == true)
                {
                    isblocked = true;
                }
                if ((input2 == false && isblockedaray[x, y] == true) || (input2 == true && isblockedaray[x, y] == false))
                {
                    isblocked = false;
                }
            }
            return isblocked;
        }
1 Like

Try adding return false or return true (whichever would fit) to the end of your function, so there’s no way for input to get through without being handled.

This should be after the last }, outside of the if block.

3 Likes

what do you mean by that

Look at my post, that will probably solve you problem in the way it was intended. Or so I hope.

I got the ancer

it turns out that all i had to do was put a

out side the if block becuase according to the stack overflow thing
" When the compiler looks at your code, it’s sees a third path (the else you didn’t code for) that could occur but doesn’t return a value. Hence not all code paths return a value.

For my suggested fix, I put a return after your loop ends. The other obvious spot - adding an else that had a return value to the if-else-if - would break the for loop."
credit to:user1345223

that means that I had to put it out side the big if block like this:

public bool method(bool whaterver){
int  nub1 1;
int nub2 1;
if(nub1 == 1){
   bool whaterver = true;
}
return whatever = true;

Which is what I suggested and what should have been marked as solution btw.

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.