How can I create overloaded methods that handle most types?
If you don't want to create a different overloaded method for each possible data type, you could create a method that accepts a parameter of type object. However, if you pass value types into this parameter, it forces .NET to "box" the value types into reference types, which wastes memory and CPU resources.
Alternately, you can create methods that accept the following parameter types:
In C#:
- long - Handles long, byte, sbyte, int, uint, short, and ushort values
- double - Handles double, float, and ulong values
- decimal - Handles decimal values
- DateTime - Handles DateTime values
In VB .NET:
- Long - Handles Boolean, Short, Integer, and Long values
- Double - Handles Single and Double values
- Decimal - Handles Decimal values
- DateTime - Handles DateTime values
- Object - Handles Strings and other reference types
© (c) 2026 Oak Leaf Enterprises, Inc., 1996-2026 • Updated: 09/22/03
Comment or report problem with topic
