Free Resources from FMS

Additional Resources

 

Thank you! Thank you! I just finished reading this document, which was part of a link in the recent Buzz newsletter. I have printed it for others to read, especially those skeptical on the powers of Access and its capabilities.

Darren D.

 

Free Catalog

 

Consider Using Static (Shared) Methods

Provided by:  Dave Juth, Senior Systems Architect

Methods that do not access instance data or instance methods can be marked static (or Shared in VB). This will allow the compiler to generate code that is more optimized for performance.

A good example:

public DataView FilterData(DataTable dt, string filterExpr)

{

   DataView dv = dt.DefaultView;

   dv.RowFilter = filterExpr;

 

   return dv;

}


This should be amended:

public static DataView FilterData(DataTable dt, string filterExpr)

{

   DataView dv = dt.DefaultView;

   dv.RowFilter = filterExpr;

 

   return dv;

}

 

As an aside: It almost does not make sense to have a generic utility method like this in a typical class that requires state and instance data, etc. A few static methods in an otherwise "traditional" looking class often indicates a problem with the design of the class. However, there may be cases where this makes sense and this can be a useful optimization.
 

Return to the tips page