使用FileInfo创建文件老是出错

bill1980 2006-09-27 08:09:37
如题,运行时老是提示“string”并不包含对“fi”的定义。
源代码如下:
using System;
using System.IO;
namespace SAMS.VisualCSharpUnleashed.Chapter7
{
class Class1
{
[STAThread]
static void Main(string[] aras)
{
//Create a new file
string filePath=@"D:\BegCSharp\test.txt";
FileInfo fi = new FileInfo(filePath);
//Print out the information if the file exists
if (fi.Exists)
{
Console.WriteLine("The file: {0} was last accessed on {1} "+
"and contains {2} bytes if data.",
filePath.fi.LastAccessTime,fi.Length);
}
else
Console.WriteLine("The file: {0} does not exist.",filePath);
Console.ReadLine();
}
}
}
...全文
177 5 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
changlongbaobao 2006-09-27
  • 打赏
  • 举报
回复
c#讨论群:30781666 欢迎有经验的高手加入
bill1980 2006-09-27
  • 打赏
  • 举报
回复
谢谢ralpha08(被水淹死的鱼)大大,问题已经解决!自己太粗心...结帖给分。
bill1980 2006-09-27
  • 打赏
  • 举报
回复
ralpha08(被水淹死的鱼)大大,具体改成什么样?能贴出来吗?
ralpha08 2006-09-27
  • 打赏
  • 举报
回复
Console.WriteLine("The file: {0} was last accessed on {1} "+
"and contains {2} bytes if data.",
filePath,fi.LastAccessTime,fi.Length);


应该是编译时报错吧! 改成这样
bill1980 2006-09-27
  • 打赏
  • 举报
回复
问题应该出在“FileInfo fi = new FileInfo(filePath);”这一句,在线等高手解救,问题解决立即结帖给分!

111,098

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • AIGC Browser
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧