gpt4 book ai didi

c# - 无法在 Visual Studio 2012 中使用 FileSystemWatcher

转载 作者:太空宇宙 更新时间:2023-11-03 18:36:49 27 4
gpt4 key购买 nike

我是 Visual Studio 和 C# 的新手。我习惯使用 XCode 和 Objective-C,但现在正在尝试编写 Windows 8 应用程序。当用户单击我的应用程序中的按钮时,我试图设置一个 FileSystemWatcher,但出于某种原因,Visual Studio 拒绝承认我可以执行此操作并引发错误。这是我写的示例:

using System;
using System.IO;
...

namespace My_APP
{
...
public sealed partial class MainPage : My_App.Common.LayoutAwarePage
{
...
public void button_click_1(object sender, RoutedEventArgs e)
{
FileSystemWatcher watch = new FileSystemWatcher();
}
}
}

FileSystemWatcher 两次都用红色下划线显示错误:错误 1 ​​找不到类型或 namespace 名称“FileSystemWatcher”(您是否缺少 using 指令或程序集引用?)我做错了什么(我确信这是非常简单的事情)。

最佳答案

因为 FileSystemWatcher 不包含在用于 Windows 8 应用程序的 .NET 版本中。如果它受支持,您会在 MSDN page 的版本信息部分看到“.NET for Windows Store apps, Supported in: Windows 8” .将此与 BinaryReader 对比,后者是 available .

Windows.Storage namespace具有用于在 Windows 8 应用程序中访问文件系统的 API。

关于c# - 无法在 Visual Studio 2012 中使用 FileSystemWatcher,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14078948/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com