相关疑难解决方法(0)

.NET是否提供了将字节转换为KB,MB,GB等的简单方法?

只是想知道.NET是否提供了一种干净的方法来执行此操作:

int64 x = 1000000;
string y = null;
if (x / 1024 == 0) {
    y = x + " bytes";
}
else if (x / (1024 * 1024) == 0) {
    y = string.Format("{0:n1} KB", x / 1024f);
}
Run Code Online (Sandbox Code Playgroud)

等等...

.net c# byte megabyte

97
推荐指数
10
解决办法
11万
查看次数

在C#中将字节转换为GB?

我正在重构一些旧代码并遇到以下代码行将字节转换为GB.

decimal GB = KB / 1024 / 1024 / 1024;
Run Code Online (Sandbox Code Playgroud)

有没有更好的方法来重构下面的代码?

更新

我的意思是说千兆字节的字节数.我提供了错误的信息.

c# refactoring

30
推荐指数
4
解决办法
4万
查看次数

将字符串格式化为KB,MB和GB

下面是返回String中数据计数器值的类.我想将String格式化为KB,MB和GB

public class MainActivity extends Activity {

 @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        TextView infoView = (TextView)findViewById(R.id.traffic_info);
        String info = "";

        long getmobilerxbytes = TrafficStats.getMobileRxBytes();
        long getmobilerxpackets = TrafficStats.getMobileRxPackets();
        long getmobiletxbytes = TrafficStats.getMobileTxBytes();
        long getmobiletxpackets = TrafficStats.getMobileTxPackets();

        long totalrxbytes = TrafficStats.getTotalRxBytes();
        long totalrxpackets = TrafficStats.getTotalRxPackets(); 
        long totaltxbytes = TrafficStats.getTotalTxBytes(); 
        long totaltxpackets = TrafficStats.getTotalTxPackets();

        info += "Mobile Interface:\n";
        info += ("\tReceived: " + getmobilerxbytes + " bytes / " + getmobilerxpackets + " packets\n");
        info += ("\tTransmitted: " + …
Run Code Online (Sandbox Code Playgroud)

string android

3
推荐指数
1
解决办法
1万
查看次数

标签 统计

c# ×2

.net ×1

android ×1

byte ×1

megabyte ×1

refactoring ×1

string ×1