#39 – MinValue / MaxValue for Numeric Types

You can access minimum and maximum values for the various built-in numeric types from your code by using the MinValue and MaxValue properties of each type.  All of the built-in numeric types have MinValue and MaxValue properties.

 byte bMin = byte.MinValue;    // 0
 byte bMax = byte.MaxValue;    // 255

 int nMin = int.MinValue;      // -2147483648
 int nMax = Int32.MaxValue;    // 2147483647

 char cMin = char.MinValue;    // 0x0000
 char cMax = char.MaxValue;    // 0xffff
Advertisements

About Sean
Software developer in the Twin Cities area, passionate about software development and sailing.

2 Responses to #39 – MinValue / MaxValue for Numeric Types

  1. Denis says:

    “All of the built-in numeric types have MinValue and MaxValue properties.” did you mean value types instead of numeric types. I think char is not a numeric type, or am i missing something?

    • Sean says:

      No, I did mean numeric types. It’s true that all numeric types have MinValue and MaxValue properties, as does the char type.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: