Return value after Exit function

  • Thread starter Thread starter sony.m.2007
  • Start date Start date
S

sony.m.2007

Hi,
I’m new to ASP.NET
I have written a function with a return value.
If the arguments to the functions are invalid means I’m giving
exit(0)
Else means do some process and return a value.
When I compile the above code, it throws error and asked for a return
value in the IF part
Error 1 : not all code paths return a value
Example Code(just to describe)



Public Arraylist Test(int a)
{
ArrayList t1 = new ArrayList();
If(a>100)
{
System.Environment.Exit(0);
Return t1
}
else
{
t1.add(“100”);
Return t 1;
}
On page load I’m calling this function
protected void Page_Load(object sender, EventArgs e)
{
Int retValue=Test(1000)
}
My question is what’s the effect of return value after Exit function?
What return value did the calling function get from test function?
Kindly explain the concept

Thanks,
Sony
 
Hi,
I’m new to ASP.NET
I have written a function with a return value.
If the arguments to the functions are invalid means I’m giving
exit(0)
Else means do some process and return a value.
When I compile the above code, it throws error and asked for a return
value in the IF part
Error   1       : not all code paths return a value
Example Code(just to describe)

Public Arraylist Test(int a)
{
ArrayList t1 = new ArrayList();
If(a>100)
{
System.Environment.Exit(0);
Return t1}

else
{
t1.add(“100”);
Return t 1;}

On page load I’m calling this function
protected void Page_Load(object sender, EventArgs e)
    {
Int retValue=Test(1000)
    }
My question is what’s the effect of return value after Exit function?
What return value did the calling function get from test function?
Kindly explain the concept

Thanks,
Sony

Sony,

Your method return an ArrayList, so you always have to return an
ArrayList.

You can use some like this:

Public Arraylist Test(int a)
{
ArrayList t1 = new ArrayList();
If(a<100)
{
t1.add(“100”);
}

Return t 1 ;


in your page use:

ArrayList retValue = Test(1000)

if ( retValue.Lenght == 0 )
{
// Do something
}


Sorry for my poor english, i am a brazilian programmer.

Regards
 
http://blogs.msdn.com/kcwalina/archive/2005/03/16/396787.aspx

I would double read and bookmark this excellent article.








Hi,
I’m new to ASP.NET
I have written a function with a return value.
If the arguments to the functions are invalid means I’m giving
exit(0)
Else means do some process and return a value.
When I compile the above code, it throws error and asked for a return
value in the IF part
Error 1 : not all code paths return a value
Example Code(just to describe)



Public Arraylist Test(int a)
{
ArrayList t1 = new ArrayList();
If(a>100)
{
System.Environment.Exit(0);
Return t1
}
else
{
t1.add(“100”);
Return t 1;
}
On page load I’m calling this function
protected void Page_Load(object sender, EventArgs e)
{
Int retValue=Test(1000)
}
My question is what’s the effect of return value after Exit function?
What return value did the calling function get from test function?
Kindly explain the concept

Thanks,
Sony
 
Back
Top