【问题标题】:C# .NET DirectoryInfo : FileSystemInfo Class membersC# .NET DirectoryInfo : FileSystemInfo 类成员
【发布时间】:2019-11-29 12:17:10
【问题描述】:

我对@9​​87654323@ 类方法的工作方式感到困惑。例如:public void Create(); 这个方法没有花括号,我只是很困惑它实际上是如何创建一个目录的?我错过了什么?

【问题讨论】:

  • "这个方法没有花括号" 你在哪里看到它是这样定义的?
  • 你在看at the docs吗?这只是文档显示方法签名的方式——这并不意味着该方法没有主体。
  • 我假设您正在使用 Visual Studio 导航到方法,这不会显示方法内容,只会显示类和方法签名。如果你想看看里面有什么,在 Github 上查看源代码或者使用工具来反编译程序集。

标签: c# .net system.io.file


【解决方案1】:

目录信息:

公开用于创建、移动和枚举的实例方法 目录和子目录。这个类不能被继承

DirectoryInfo.Create :

用于创建目录。

示例:

    DirectoryInfo directory = new DirectoryInfo("you path directory");

    try 
    {
        // check if you directory exists.
        if (directory.Exists) 
        {
            // if you directory exists.
            return;
        }

        //otherwise you create you directory.
        directory.Create();

    } 
    catch (Exception e) 
    {
        Console.WriteLine("The process failed: {0}", e.ToString());
    } 

来源: https://docs.microsoft.com/en-us/dotnet/api/system.io.directoryinfo?view=netframework-4.8

【讨论】:

    【解决方案2】:

    您只能看到它的方法名称,因为这只是通过 C# 向您展示公共方法的一种方式,如果您不拥有库的源代码,您将看不到库的代码!

    【讨论】:

      猜你喜欢
      • 2023-03-08
      • 1970-01-01
      • 2018-09-28
      • 1970-01-01
      • 1970-01-01
      • 2011-08-23
      • 2014-08-14
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多