[英]C# Modulus Counting
美好的一天,
我正在編寫一個應用程序,用於下載30MB以上的文件。 我跟蹤當前已下載了多少字節。
我的問題是:
我想確定何時超過1M,2M,3M等。
我的邏輯是:
int totalFileSave = 0;
...
...
int bytesRead = responseStream.Read(buffer, 0, 4096);
totalFileSave += bytesRead;
while (bytesRead > 0) {
// How do I test when I hit 1M, 2M, 3M and so forth...
bytesRead = responseStream.Read(buffer, 0, 4096);
totalFileSave += bytesRead;
}
private const int MEGABYTE = 1024 * 1024;
if ((bytesRead % MEGABYTE) == 0)
{
// Do something...
}
這樣的事情怎么樣:
private const int megaByte = 1024 * 1024;
private int current = 0;
while (bytesRead > 0)
{
bytesRead = responseStream.Read(buffer, 0, 4096);
totalFileSave += bytesRead;
int total = bytesRead / megaByte;
if (total > current)
{
current = total;
// you went up 1 M and are now at or greater than 'current'M
}
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.