我可以在另一个方法中调用静态方法吗?

2 c# methods static class

基本问题:如何在另一个方法中调用静态方法.请帮忙!!

public static class Class1
{
  public static string RenderCompareStatus()
  {
      bool isFound = Class1.Found(id);
  }

  private static bool Found(string id)
  {

  }
Run Code Online (Sandbox Code Playgroud)

//错误消息:不包含Found的定义

Gra*_*ner 5

我将您的示例扩展为一个完整的示例:

using System;

public static class Class1
{
    public static void Main()
    {
        Console.WriteLine(RenderCompareStatus());
    }

    public static string RenderCompareStatus()
    {
        String id = "test";
        bool isFound = Found(id);
        return "Test: " + isFound;
    }

    private static bool Found(string id)
    {
        return false;
    }
}
Run Code Online (Sandbox Code Playgroud)

结果如下:

Test: False
Run Code Online (Sandbox Code Playgroud)

编辑:如果上面的示例与您的代码类似,但您的代码不起作用,请编辑您的问题,提供更多详细信息,例如您获得的准确错误以及产生错误的代码的更完整示例.

编辑:更改public static bool Found(string id)private static bool Found(string id)重新编译,它仍然有效.