【问题标题】:Calling a public method from Main()从 Main() 调用公共方法
【发布时间】:2013-03-09 19:38:24
【问题描述】:

如何在下面的程序中调用GetDFT() 方法?

namespace Lott_CSC445_Project6
{
    class Program
    {    
        ... // declarations removed for brevity

        static void Main(string[] args)
        {
            ... // some code

            GetDFT() // <<< Call the method here

            ... // more code
        }

        public void GetDFT()
        {
            ... // method body removed for brevity
        }    
    }
}

【问题讨论】:

标签: c# methods console


【解决方案1】:

方法不是static,所以是Programinstance方法。

这意味着您需要一个 Program 的实例来调用它。

或者,创建方法static

【讨论】:

  • 如果我将其设为静态,则 GetDFT 中的 boolMatrix 函数将不起作用。
  • @JLott - 出于几乎相同的原因。
猜你喜欢
  • 2015-12-17
  • 1970-01-01
  • 2011-09-19
  • 2011-08-16
  • 2015-08-26
  • 1970-01-01
  • 2019-11-23
  • 1970-01-01
  • 2014-08-06
相关资源
最近更新 更多