Posts Tagged ‘tips’

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

  • Share/Bookmark

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.

  • Share/Bookmark

Download and feed at the same time

Yeah I know, everybody hates it including me “at the time i became a web dev and realized how horrible it was”.

But for all these negative side effects the browser has…there’s a catch.

Please read this

  • Share/Bookmark
Return top

DISCLAIMER

Due to my superb English vocabulary, users are still encourage to use dictionary and thesaurus for your references :D
 

Switch to our mobile site