Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > Variable scope question

Reply
Thread Tools

Variable scope question

 
 
GS
Guest
Posts: n/a
 
      01-08-2006
Hello,

I have following code below. I need to pass object action to SetReturnURL method but compiler will not compile it becouse action is defined within "if" block.
How do I define action before if statement?

if (ReturnCall.ApplicationDisplayName == "")
{
ModifyActionCodeType action = ModifyActionCodeType.Add;
}
else
{
ModifyActionCodeType action = ModifyActionCodeType.Update;
}
try
{
call.SetReturnURL(action,System.Web.Configuration. WebConfigurationManager..AppSettings["DisplayName"], aet);
}

 
Reply With Quote
 
 
 
 
=?Utf-8?B?U2VyZ2V5IFBvYmVyZXpvdnNraXk=?=
Guest
Posts: n/a
 
      01-08-2006
Just define your action BEFORE the if statement:
ModifyActionCodeType action;
if (ReturnCall.ApplicationDisplayName == "")
{
action = ModifyActionCodeType.Add;
}
else
{
action = ModifyActionCodeType.Update;
}

or use a short-hand syntax:

ModifyActionCodeType action = (ReturnCall.ApplicationDisplayName == "") ?
ModifyActionCodeType.Add : ModifyActionCodeType.Update;

"GS" wrote:

> Hello,
>
> I have following code below. I need to pass object action to SetReturnURL method but compiler will not compile it becouse action is defined within "if" block.
> How do I define action before if statement?
>
> if (ReturnCall.ApplicationDisplayName == "")
> {
> ModifyActionCodeType action = ModifyActionCodeType.Add;
> }
> else
> {
> ModifyActionCodeType action = ModifyActionCodeType.Update;
> }
> try
> {
> call.SetReturnURL(action,System.Web.Configuration. WebConfigurationManager..AppSettings["DisplayName"], aet);
> }
>

 
Reply With Quote
 
 
 
 
GS
Guest
Posts: n/a
 
      01-08-2006
ηΕΞΙΚ
"Sergey Poberezovskiy" <(E-Mail Removed)> wrote
in message news:(E-Mail Removed)...
> Just define your action BEFORE the if statement:
> ModifyActionCodeType action;
> if (ReturnCall.ApplicationDisplayName == "")
> {
> action = ModifyActionCodeType.Add;
> }
> else
> {
> action = ModifyActionCodeType.Update;
> }
>
> or use a short-hand syntax:
>
> ModifyActionCodeType action = (ReturnCall.ApplicationDisplayName == "") ?
> ModifyActionCodeType.Add : ModifyActionCodeType.Update;
>
> "GS" wrote:
>
>> Hello,
>>
>> I have following code below. I need to pass object action to SetReturnURL
>> method but compiler will not compile it becouse action is defined within
>> "if" block.
>> How do I define action before if statement?
>>
>> if (ReturnCall.ApplicationDisplayName == "")
>> {
>> ModifyActionCodeType action = ModifyActionCodeType.Add;
>> }
>> else
>> {
>> ModifyActionCodeType action = ModifyActionCodeType.Update;
>> }
>> try
>> {
>> call.SetReturnURL(action,System.Web.Configuration. WebConfigurationManager..AppSettings["DisplayName"],
>> aet);
>> }
>>



 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Having trouble understanding function scope and variable scope Andrew Falanga Javascript 2 11-22-2008 09:23 PM
Scope - do I need two identical classes, each with different scope? ann Java 13 09-13-2005 03:07 AM
How do namespace scope and class scope differ? Steven T. Hatton C++ 9 07-19-2005 06:07 PM
IMPORT STATIC; Why is "import static" file scope? Why not class scope? Paul Opal Java 12 10-10-2004 11:01 PM
How do I scope a variable if the variable name contains a variable? David Filmer Perl Misc 19 05-21-2004 03:55 PM



Advertisments