fileinfo什么意思,是什么在C#中的文件和FileInfo的区别?

I've been reading that the static methods of the File Class are better used to perform small and few tasks on a file like checking to see if it exists and that we should use an instance of the FileInfo Class if we are going to perform many operations on a specific file.

I understand this and can simply use it that way blindly but I would like to know why is there a difference ? What is it about the way they work that make them suitable for different situations ? What is the point of having this 2 different classes that seem do the same in different ways ?

It would be helpful if someone could answer at least one of this questions.

解决方案

Generally if you are performing a single operation on a file, use the File class. If you are performing multiple operations on the same file, use FileInfo.

The reason to do it this way is because of the security checking done when accessing a file. When you create an instance of FileInfo, the check is only performed once. However, each time you use a static File method the check is performed.

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值