新的FileInfo(路径).Name点与Path.GetFileName(路径) [英] new FileInfo(path).Name versus Path.GetFileName(path)
本文介绍了新的FileInfo(路径).Name点与Path.GetFileName(路径)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
哪一个更好用,为什么? 我的意思是在哪些方面这两个命令的不同又如何? 性能方面,可读性,...
which one is better to use and why? I mean in which aspects these two commands differ and how? Performance, readability, ...
新的FileInfo(路径),请将.Name
或 Path.GetFileName(路径)
推荐答案
只要你将不必创建新的对象,使用Path.GetFilename(),它会表现得更好。
Simply as you won't have to Create a new Object for using Path.GetFilename() it will perform better.
下面是一个比较为:
code:
Path.GetFileName("G:\\u.png")
IL:
IL_0000: ldstr "G:\u.png"
IL_0005: call System.IO.Path.GetFileName
code:
Code:
new FileInfo("G:\\u.png").Name
IL:
IL_0000: ldstr "G:\u.png"
IL_0005: newobj System.IO.FileInfo..ctor
IL_000A: callvirt System.IO.FileSystemInfo.get_Name
这篇关于新的FileInfo(路径).Name点与Path.GetFileName(路径)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文