Is there an easy way to determine font size in C #?

Is there a way to say something like:

SizeOf (type)? Or enter. The size?

Now I'm looking at using code like:

if (type.Equals(typeof(int))) return sizeof(int); else if (type.Equals(typeof(long))) return sizeof(long); 

etc. for each individual data type.

There should be a cleaner solution, no?

+7
c #
source share
4 answers
+13
source share

If it's for data access, you can do type.GetTypeCode () (which is a member of IConvertible), which gives you a good listing for inclusion.

+1
source share

Take a look at these questions:

In particular, read the answers posted by Jon Skeet .

+1
source share

Maybe you can go Convert.ToString(type.MaxValue, 2).Length / 8

-4
source share

All Articles