Return value after Exit function

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
 
E

Eugenio

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
 
S

sloan

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,772
Messages
2,569,593
Members
45,111
Latest member
KetoBurn
Top