FileSizeFormatProvider
全部标签 有没有什么简单的方法可以创建一个使用IFormatProvider的类来写出用户友好的文件大小?publicstaticstringGetFileSizeString(stringfilePath){FileInfoinfo=newFileInfo(@"c:\windows\notepad.exe");longsize=info.Length;stringsizeString=size.ToString(FileSizeFormatProvider);//Thisiswheretheclassdoesitsmagic...}它应该产生格式为“2,5MB”、“3,9GB”、“670字节”
有没有什么简单的方法可以创建一个使用IFormatProvider的类来写出用户友好的文件大小?publicstaticstringGetFileSizeString(stringfilePath){FileInfoinfo=newFileInfo(@"c:\windows\notepad.exe");longsize=info.Length;stringsizeString=size.ToString(FileSizeFormatProvider);//Thisiswheretheclassdoesitsmagic...}它应该产生格式为“2,5MB”、“3,9GB”、“670字节”