新的FileInfo(路径).Name点与Path.GetFileName(路径)路径、FileInfo、Name、GetFileName

由网友(客套感情)分享简介:哪一个更好用,为什么?我的意思是在哪些方面这两个命令的不同又如何?性能方面,可读性,... which one is better to use and why?I mean in which aspects these two commands differ and how?Performance, rea...

哪一个更好用,为什么? 我的意思是在哪些方面这两个命令的不同又如何? 性能方面,可读性,...

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
阅读全文

相关推荐

最新文章