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 Path.GetFileName(path)
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Simply as you won’t have to Create a new Object for using Path.GetFilename() it will perform better.
Here is a Comparison for both:
Code:
IL:
Code:
IL: