new FileInfo(path).Name versus Path.GetFileName(path)

后端 未结 3 543
醉梦人生
醉梦人生 2020-12-09 19:28

which one is better to use and why? I mean in which aspects these two commands differ and how? Performance, readability, ...

new FileInfo(path).Name or

3条回答
  •  南方客
    南方客 (楼主)
    2020-12-09 20:01

    I'd suggest using Path.GetFilename() because it simply parses path and returns file name. On other hand FileInfo object will check if executed code has rights to access specified file which is relatively slow.

提交回复
热议问题