我正要使用FileUpload.FileBytes財產,但尋找到各自的例子在MSDN庫我感到困惑的這一部分:ASP:FileUpload.FileBytes例如在MSDN混亂
int fileLen;
// Get the length of the file.
fileLen = FileUpload1.PostedFile.ContentLength;
// Create a byte array to hold the contents of the file.
byte[] input = new byte[fileLen - 1];
input = FileUpload1.FileBytes;
(從here,我省略了一些不重要的行)
在這段代碼中的new
尋找我喜歡的食物垃圾收集器沒有用。 (可能大的食物,如果該文件是大)他們爲什麼不乾脆寫:
byte[] input = FileUpload1.FileBytes;
我太新,.NET和C#要勇敢地宣佈這根本是多餘的或壞的書面例子。它是否有任何目的(也許是性能好處等)? (我也不明白他們爲什麼會從fileLen
中減去1.)
我能想到的唯一的事情是編寫樣本的人將使用他們的輸入數組作爲FileUpload1.FileBytes.CopyTo(...)或類似的東西。我沒有理由創建字節數組,然後將FileBytes分配給它。 – 2010-03-01 19:55:05