Connecting Tech Pros Worldwide Help | Site Map

Return value after Exit function

sony.m.2007@googlemail.com
Guest
 
Posts: n/a
#1: Jun 27 '08
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
Patrice
Guest
 
Posts: n/a
#2: Jun 27 '08

re: Return value after Exit function


Have you tried the doumentation first ?

http://msdn.microsoft.com/en-us/libr...ment.exit.aspx could
help (Basically you try to terminate the process (not the function whihc is
what Return does anyway) which is likely not what you want).

If the parameter is not valid, you could just throw an exception. Also is
the function supposed to return an ArrayList or an Integer ?

--
Patrice

<sony.m.2007@googlemail.coma écrit dans le message de groupe de discussion
: 3cc934e1-d882-4481-89bf-42a32f6818a6...oglegroups.com...
Quote:
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

Eugenio
Guest
 
Posts: n/a
#3: Jun 27 '08

re: Return value after Exit function


On Jun 17, 9:45*am, sony.m.2...@googlemail.com wrote:
Quote:
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
sloan
Guest
 
Posts: n/a
#4: Jun 27 '08

re: Return value after Exit function



http://blogs.msdn.com/kcwalina/archi...16/396787.aspx

I would double read and bookmark this excellent article.








<sony.m.2007@googlemail.comwrote in message
news:3cc934e1-d882-4481-89bf-42a32f6818a6@i76g2000hsf.googlegroups.com...
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


Closed Thread