How will be faster get the file extension
如何更快地获得文件扩展名
string ext = System.IO.Path.GetExtension(FileName);
string ext=FileName.Substring(FileName.LastIndexOf('.'));
System.IO.FileInfo fi = new System.IO.FileInfo(FileName);
string ext = fi.Extension;
string[] temp= FileName.Split('.');
string ext =temp[temp.Length-1];
System.Text.RegularExpressions.Regex extend = new
System.Text.RegularExpressions.Regex(@"(?:.*\.)(.*)");
string ext = extend.Match(FileName).Groups[1].Value;
1 个解决方案
#1
2
In case of such operations your first concern should be which one is more idiomatic, maintainable and readable. The first and the third version are examples of these. In the second and the last one you're trying to reinvent the wheel, making the code less readable and more error prone.
在这种操作的情况下,您首先要关注的是哪一个更具惯用性,可维护性和可读性。第一个和第三个版本就是这些的例子。在第二个也是最后一个,你试图重新发明*,使代码更不易读,更容易出错。
In VM frameworks performance is achieved through higher-level optimisations, like controlling the number of allocated objects, references between them etc. Things you talk about here are minor and probably irrelevant in terms of performance.
在VM框架中,性能是通过更高级别的优化来实现的,例如控制已分配对象的数量,它们之间的引用等。您在这里谈论的内容很小,可能在性能方面无关紧要。
#1
2
In case of such operations your first concern should be which one is more idiomatic, maintainable and readable. The first and the third version are examples of these. In the second and the last one you're trying to reinvent the wheel, making the code less readable and more error prone.
在这种操作的情况下,您首先要关注的是哪一个更具惯用性,可维护性和可读性。第一个和第三个版本就是这些的例子。在第二个也是最后一个,你试图重新发明*,使代码更不易读,更容易出错。
In VM frameworks performance is achieved through higher-level optimisations, like controlling the number of allocated objects, references between them etc. Things you talk about here are minor and probably irrelevant in terms of performance.
在VM框架中,性能是通过更高级别的优化来实现的,例如控制已分配对象的数量,它们之间的引用等。您在这里谈论的内容很小,可能在性能方面无关紧要。