ExtensionMethod.NET Home of 880 C#, Visual Basic, F# and Javascript extension methods

KB,MB,GB,TB

Simplest way to get a number of bytes at different measures. KB, MB, GB or TB,

Source

/// <summary>
/// Kilobytes
/// </summary>
/// <param name="value"></param>
/// <returns></returns>
public static int KB(this int value)
{
	return value * 1024;
}

/// <summary>
/// Megabytes
/// </summary>
/// <param name="value"></param>
/// <returns></returns>
public static int MB(this int value)
{
	return value.KB() * 1024;
}

/// <summary>
/// Gigabytes
/// </summary>
/// <param name="value"></param>
/// <returns></returns>
public static int GB(this int value)
{
	return value.MB() * 1024;
}

/// <summary>
/// Terabytes
/// </summary>
/// <param name="value"></param>
/// <returns></returns>
public static long TB(this int value)
{
	return (long)value.GB() * (long)1024;
}

Example

var 1kb = 1.KB();
var 1mb = 1.MB();
var 1gb = 1.GB();
var 1tb = 1.TB();

Author: José Fidalgo H.

Submitted on: 13 jun. 2013

Language: C#

Type: System.Int32

Views: 7792