string problem

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Dave Bailey

    string problem

    I am trying to use an if statement to obtain a return value to use somewhere else in my program. Can you look at this code and tell me what needs to be added to the code to keep from getting an unassigned local variable sortParameter error



    public string SortParameter(



    string sortParamete

    if (fiscalYearChec k.Checked == true



    sortParameter = "wo11"



    else if (custCheck.Chec ked == true



    sortParameter = "wopm2"



    return sortParameter





    Thanks



    Dav

  • Nicholas Paldino [.NET/C# MVP]

    #2
    Re: string problem

    Dave,

    You can just declare your variable like this:

    string sortParameter = null;

    Hope this helps.


    --
    - Nicholas Paldino [.NET/C# MVP]
    - mvp@spam.guard. caspershouse.co m

    "Dave Bailey" <anonymous@disc ussions.microso ft.com> wrote in message
    news:70192BF0-557D-403A-8CE6-288F8005DC2C@mi crosoft.com...[color=blue]
    > I am trying to use an if statement to obtain a return value to use[/color]
    somewhere else in my program. Can you look at this code and tell me what
    needs to be added to the code to keep from getting an unassigned local
    variable sortParameter error.[color=blue]
    >
    >
    >
    > public string SortParameter()
    >
    > {
    >
    > string sortParameter
    >
    > if (fiscalYearChec k.Checked == true)
    >
    > {
    >
    > sortParameter = "wo11";
    >
    > }
    >
    > else if (custCheck.Chec ked == true)
    >
    > {
    >
    > sortParameter = "wopm2";
    >
    > }
    >
    > return sortParameter;
    >
    > }
    >
    >
    >
    > Thanks,
    >
    >
    >
    > Dave
    >[/color]


    Comment

    • Marco Martin

      #3
      Re: string problem

      Dave,

      Try doing this;

      string sortParameter = null;

      this way the string is assigned a value. thus no error

      HTH
      Marco
      "Dave Bailey" <anonymous@disc ussions.microso ft.com> wrote in message
      news:70192BF0-557D-403A-8CE6-288F8005DC2C@mi crosoft.com...[color=blue]
      > I am trying to use an if statement to obtain a return value to use[/color]
      somewhere else in my program. Can you look at this code and tell me what
      needs to be added to the code to keep from getting an unassigned local
      variable sortParameter error.[color=blue]
      >
      >
      >
      > public string SortParameter()
      >
      > {
      >
      > string sortParameter
      >
      > if (fiscalYearChec k.Checked == true)
      >
      > {
      >
      > sortParameter = "wo11";
      >
      > }
      >
      > else if (custCheck.Chec ked == true)
      >
      > {
      >
      > sortParameter = "wopm2";
      >
      > }
      >
      > return sortParameter;
      >
      > }
      >
      >
      >
      > Thanks,
      >
      >
      >
      > Dave
      >[/color]


      Comment

      • Dave Bailey

        #4
        Re: string problem

        That worked great.

        Thanks,

        dave

        Comment

        Working...