更新时间:2023-11-28 23:17:28
它将返回。广州,而是从MSDN(解释的FileSystemInfo.Extension物业)目前尚不清楚为什么:
It will return .gz, but the explanation from MSDN (FileSystemInfo.Extension Property) isn't clear why:
的的扩展属性返回FileSystemInfo扩展,包括句例如,对于一个文件c():\NewFile.txt,此属性返回.TXT
于是我抬起头,反射器扩展
属性代码:
So I looked up the code of the Extension
property with reflector:
public string Extension
{
get
{
int length = this.FullPath.Length;
int startIndex = length;
while (--startIndex >= 0)
{
char ch = this.FullPath[startIndex];
if (ch == '.')
{
return this.FullPath.Substring(startIndex, length - startIndex);
}
if (((ch == Path.DirectorySeparatorChar) || (ch == Path.AltDirectorySeparatorChar)) || (ch == Path.VolumeSeparatorChar))
{
break;
}
}
return string.Empty;
}
}
这是从文件路径的末尾,直到检查每一个字符它找到一个点,那么子从点到文件路径的末尾返回。
It's check every char from the end of the filepath till it finds a dot, then a substring is returned from the dot to the end of the filepath.