我想获取要在ListView中显示的大小。但是我的代码返回0。我发现.Length()获得长度大小,但只有Count(),它不能解决我的问题。
我的代码如下:
string[] filePaths = (string[])e.Data.GetData(DataFormats.FileDrop, false);
List<FileInfo> fileInfos = new List<FileInfo>();
foreach (string filePath in filePaths)
{
FileInfo f = new FileInfo(filePath);
fileInfos.Add(f);
long s1 = fileInfos.Count;
string chkExt = Path.GetExtension(f.ToString());
s1 = s1/1024;
decimal d = default(decimal);
d = decimal.Round(s1, 2, MidpointRounding.AwayFromZero);
// d is 0. Because s1 = 1 only count not length of file.
您正在使用fileInfos
,这是一个List<T>
。您要检查实际FileInfo的长度f
:
long s1 = f.Length;
当您除以1024时,请注意,处理文件zizi的单位有所不同,具体取决于您的基数:2或10。KB为2 ^ x,kB为10 ^ x字节。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句