Filesize convertion in c#

Just for sharing, I found this small code from this site and this is the easiest way for converting bytes (because I’m a Math guru who repeated College Algebra by 5 times that is why I picked this code rather dividing large numbers to 1024 by 1024 and so on…).So let Microsoft do the Math Okay! .

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
        private string ToFileSize(long source)
        {
            const int byteConversion = 1024;
            double bytes = Convert.ToDouble(source);
 
            if (bytes >= Math.Pow(byteConversion, 4)) //TB Range
            {
                return string.Concat(Math.Round(bytes / Math.Pow(byteConversion, 4), 2), " TB");
            }
            if (bytes >= Math.Pow(byteConversion, 3)) //GB Range
            {
                return string.Concat(Math.Round(bytes / Math.Pow(byteConversion, 3), 2), " GB");
            }
            else if (bytes >= Math.Pow(byteConversion, 2)) //MB Range
            {
                return string.Concat(Math.Round(bytes / Math.Pow(byteConversion, 2), 2), " MB");
            }
            else if (bytes >= byteConversion) //KB Range
            {
                return string.Concat(Math.Round(bytes / byteConversion, 2), " KB");
            }
            else //Bytes
            {
                return string.Concat(bytes, " Bytes");
            }
        }

Another useful diagram I found (sorry but i lost the source of this picture, an apology to the author)

kilobyte

The CamelCase

NO! that was not what I mean(*meant) (as opposed on the other term used on(*in) the dark industry).

For developers/programmers this practice should be well much understood and as for me,much better to use than the traditional “strVariableName” or “intVariableName”. Please read more about this in wiki

*Citation needed. Please read the site disclaimer above.

A brand new start

Yesterday evening just minutes before the start of my daily routine work (of sleeping..just kidding!) I got a call from someone that I am waiting and praying for the past couple of days that maybe a start of my new better life and a career that Im dreaming of…

Goodluck to me.

PS: A million thanks to you Mr. Menno!