Send a suggestion!

We're building a brand new version of the site, and we'd love to hear your ideas

Members

Technology Zones

IBM Learning Center

Articles

Hosted By

MaximumASP

Info

Refactoring/Optimizing code

Last post 07-08-2008 6:10 PM by TimL. 5 replies.
Page 1 of 1 (6 items)
Sort Posts: Previous Next
  • 07-07-2008 5:34 PM

    • MB34
    • Not Ranked
    • Joined on 11-22-2005
    • New Member
    • Points 55

    Refactoring/Optimizing code

    Using FXCop to optimize and refactor application, how do I get rid of the avoid unused private fields notification in the code below? If I use one dummy field, I'll still get the notification.

    Dim sHGBvalue, sHGBdate As String
    .
    .
    dreader = SQLCommand.ExecuteReader(CommandBehavior.SingleRow)
    If dreader.Read() Then
      sHGBvalue = dreader(0)
      sHGBdate = dreader(1)
    End If
    dreader.Close()

    Do I really need to assign the dreader(0) and dreader(1) to
    anything at all? Can't I just use this:

    If dreader.Read() Then
    End If
    dreader.Close()
    • Post Points: 10
  • Advertisement

    • Red Gate Software

    Advertisement

    Want to boost your .NET application performance?

    Some developers always seem to write efficient and lightening-fast code. What is their secret? It’s ANTS Profiler. “We improved the performance of the application up to 10 times” Dan Ports, Intrigma.

    Try it for yourself now.

  • 07-07-2008 11:44 PM In reply to

    • TimL
    • Top 100 Contributor
    • Joined on 07-02-2007
    • United Kingdom
    • Fanatic Member
    • Points 1,685

    Re: Refactoring/Optimizing code

    I can't exactly see why you're getting this error in the code above.

    Are you sure you don't have any other private fields in your class which are not being assigned to?


    • Post Points: 10
  • 07-08-2008 2:00 PM In reply to

    • MB34
    • Not Ranked
    • Joined on 11-22-2005
    • New Member
    • Points 55

    Re: Refactoring/Optimizing code

    The message is:

    "It appears that field 'fclsChemoOrder.sHGBdate' is never used or is only ever assigned to. Use this field or remove it"

    {http://msdn.microsoft.com/en-us/ms245042.aspx}

    I've got tons of these in my report and am taking care of most of them. It's ones like this that I'm trying to fix. Will using the second snippet circumvent the problem?

     

    • Post Points: 10
  • 07-08-2008 2:43 PM In reply to

    • TimL
    • Top 100 Contributor
    • Joined on 07-02-2007
    • United Kingdom
    • Fanatic Member
    • Points 1,685

    Re: Refactoring/Optimizing code

    From what you're saying, it appears you get this error because the variables are not used after you've assigned values to them. If you use sHGBdate elsewhere in your code, the message should go away.

    In terms of using the second snippet, what exactly are you trying to do? The code opens a data reader but you're not doing anything with the results.  

     

    • Post Points: 10
  • 07-08-2008 4:59 PM In reply to

    • MB34
    • Not Ranked
    • Joined on 11-22-2005
    • New Member
    • Points 55

    Re: Refactoring/Optimizing code

    If you use sHGBdate elsewhere in your code, the message should go away.

    I *know* that but there is no reason to use those variables later.

    AFA the second snippet, it looks like the first snippet is only moving the data pointer in dreader and I

    didn't want to have 2 unused varaibles for nothing, plus, personally, I don't think ANY of the code is really

    needed. Comments?

    • Post Points: 10
  • 07-08-2008 6:10 PM In reply to

    • TimL
    • Top 100 Contributor
    • Joined on 07-02-2007
    • United Kingdom
    • Fanatic Member
    • Points 1,685

    Re: Refactoring/Optimizing code

    If you don't think any of the code is really necessary, I would suggest removing it and see what happens! It's quite hard for me comment without a more rounded understanding of what exactly the code does.

    Good luck!! 

     

    • Post Points: 5
Page 1 of 1 (6 items)