'场',但用于像一个“类型” [英] 'field' but is used like a 'type'

查看:179
本文介绍了'场',但用于像一个“类型”的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我收到了,我似乎无法找出一条错误消息。我看到有张贴许多其他类似的问题,但解决方案似乎并不为我工作。

错误消息:

 'PaymentPlanStoreLogic.Class1.myLog'是一种'场',但用于像一个类型
 

我的code:

 使用系统;
使用PaymentPlanLogic;
命名空间PaymentPlanStoreLogic
{
  公共类的Class1
  {
    记录仪myLog =新记录仪();
    myLog.createLog();
   }
}
 

对象浏览器:

 公共无效createLog()
PaymentPlanLogic.Logger会员
 

我已经尝试了以下的建议在页面上 (对象)是一种'场',但用于像一个类型

  PaymentPlanLogic.Logger.createLog();
 

但我得到的错误

 'PaymentPlanLogic.Logger.createLog()'是'方法',但用于像一个类型
 

解决方案

您不能在外地调用的方法的方法外:

 使用系统;
使用PaymentPlanLogic;
命名空间PaymentPlanStoreLogic
{
  公共类的Class1
  {
    记录仪myLog =新记录仪();

    无效YouForgotThisMethod()
    {
      myLog.createLog();
    }
  }
}
 

I'm getting an error message that I can't seem to figure out. I see that there are many other similar questions posted but the solutions don't seem to be working for me.

Error Message:

'PaymentPlanStoreLogic.Class1.myLog' is a 'field' but is used like a 'type'

My Code:

using System;
using PaymentPlanLogic;
namespace PaymentPlanStoreLogic
{
  public class Class1
  {
    Logger myLog = new Logger();
    myLog.createLog();
   }
}

Object Browser:

public void createLog()
Member of PaymentPlanLogic.Logger

I have tried the following as suggested on the page (object) is a 'field' but is used like a 'type'

PaymentPlanLogic.Logger.createLog();

But I get the error

"'PaymentPlanLogic.Logger.createLog()' is a 'method' but is used like a 'type'"

解决方案

You can't call a method on a field outside of a method:

using System;
using PaymentPlanLogic;
namespace PaymentPlanStoreLogic
{
  public class Class1
  {
    Logger myLog = new Logger();

    void YouForgotThisMethod()
    {
      myLog.createLog();
    }
  }
}

这篇关于'场',但用于像一个“类型”的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆