Variable scope question

Discussion in 'ASP .Net' started by GS, Jan 8, 2006.

  1. GS

    GS Guest

    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);
    }
     
    GS, Jan 8, 2006
    #1
    1. Advertising

  2. 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);
    > }
    >
     
    =?Utf-8?B?U2VyZ2V5IFBvYmVyZXpvdnNraXk=?=, Jan 8, 2006
    #2
    1. Advertising

  3. GS

    GS Guest

    çÅÎÉÊ
    "Sergey Poberezovskiy" <> wrote
    in message news:...
    > 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);
    >> }
    >>
     
    GS, Jan 8, 2006
    #3
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Paul Opal
    Replies:
    12
    Views:
    986
    Paul Opal
    Oct 11, 2004
  2. ann
    Replies:
    13
    Views:
    689
    Patricia Shanahan
    Sep 13, 2005
  3. Steven T. Hatton
    Replies:
    9
    Views:
    510
  4. David Filmer
    Replies:
    19
    Views:
    267
    Kevin Collins
    May 21, 2004
  5. Andrew Falanga
    Replies:
    2
    Views:
    208
    Andrew Falanga
    Nov 22, 2008
Loading...

Share This Page