Click here to Skip to main content
15,918,967 members
Please Sign up or sign in to vote.
2.00/5 (1 vote)
See more:
Hi friends,

What's the problem of my code that gives me an error?
C#
public int f()
{
    int x = 8;
        int y = 8;

    PictureBox[,] pic = new PictureBox[8, 8];
    for (int i = 0; i < x; i++)
    {
        for (int j = 0; j < y; j++)
        {
            pic[i, j] = pictureBox34;
            Console.WriteLine(String.Format("[i,j] = [{0},{1},{2}]", i, j));
        }
    }
...
...
Posted
Updated 3-Dec-10 4:18am
v3
Comments
Dalek Dave 3-Dec-10 10:16am    
Edited for Syntax and Readability.

Your method returns an int

public int f()

So, it has to return a value


C#
public int f()
{
    int x = 8;
        int y = 8;
    PictureBox[,] pic = new PictureBox[8, 8];
    for (int i = 0; i < x; i++)
    {
        for (int j = 0; j < y; j++)
        {
            pic[i, j] = pictureBox34;
            Console.WriteLine(String.Format("[i,j] = [{0},{1},{2}]", i, j));
        }
    }

    return x; // what do you want to return??
}


If you don't need a return value, use void

public void f()
 
Share this answer
 
Hi Arash,

the function you posted isn't complete, but from your compilation error I can see that you're not returning an int in some code paths.
This means that further down in your fucntion you have some if statments
and there are return statements in some but not all branches.
And for sure there is no return statment right before the closing brace of the function definition.

If I need to do more explaining, please feel free to post a comment to this answer.

Cheers,


Manfred
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900