473,382 Members | 1,647 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,382 software developers and data experts.

Variable scope question

GS
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);
}

Jan 8 '06 #1
2 995
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);
}

Jan 8 '06 #2
GS
ηΕΞΙΚ
"Sergey Poberezovskiy" <Se*****************@discussions.microsoft.com> wrote
in message news:70**********************************@microsof t.com...
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);
}

Jan 8 '06 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

7
by: YGeek | last post by:
Is there any difference between declaring a variable at the top of a method versus in the code of the method? Is there a performance impact for either choice? What about if the method will return...
3
by: Grant Wagner | last post by:
Given the following working code: function attributes() { var attr1 = arguments || '_'; var attr2 = arguments || '_'; return ( function (el1, el2) { var value1 = el1 + el1; var value2 = el2...
134
by: James A. Donald | last post by:
I am contemplating getting into Python, which is used by engineers I admire - google and Bram Cohen, but was horrified to read "no variable or argument declarations are necessary." Surely that...
44
by: Mohanasundaram | last post by:
int i = 10; int main() { int i = 20; return 0; } Hi All, I want to access the global variable i inside the main. Is there
4
by: Gery D. Dorazio | last post by:
Gurus, If a static variable is defined in a class what is the scope of the variable resolved to for it to remain 'static'? For instance, lets say I create a class library assembly that is...
23
by: Russ Chinoy | last post by:
Hi, This may be a totally newbie question, but I'm stumped. If I have a function such as: function DoSomething(strVarName) { ..... }
5
by: somenath | last post by:
Hi All , I have one question regarding scope and lifetime of variable. #include <stdio.h> int main(int argc, char *argv) { int *intp = NULL; char *sptr = NULL;
112
by: istillshine | last post by:
When I control if I print messages, I usually use a global variable "int silent". When I set "-silent" flag in my command line parameters, I set silent = 1 in my main.c. I have many functions...
3
by: SRoubtsov | last post by:
Dear all, Do you know whether ANSI C (or some other dialects) support the following: * a variable name coincides with a type name, * a structure/union field name coincides with a type name in...
9
by: Erwin Moller | last post by:
Hi all, Is it possible (PHP5.2) to find the name of a variable used in the caller of a function from within the function itself? Or to be more clear: ...php code.. $result = foo($abc);...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.