当前上下文中不存在名称"temp"(C#桌面应用程序) [英] The name 'temp' does not exist in the current context (C# desktop application)

查看:214
本文介绍了当前上下文中不存在名称"temp"(C#桌面应用程序)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用以下代码制作C#桌面应用程序:

I am making a C# desktop application with following code:

static class ClassA
{
     public static string Process()
     {
          string temp = Functions.Test();
          return temp;
     }
}

static class Functions
{
     public static string Test()
     {
          return "ok";
     }
}

问题是变量"temp"没有从Test()函数获得任何值.当我尝试在即时窗口"中检查其值时,收到消息名称'temp'在当前上下文中不存在"

Problem is the variable "temp" doesn't get any value from Test() funciton. When I try to check its value in Immediate Window, I get the message "The name 'temp' does not exist in the current context"

ClassA和Function都位于单独的类文件中,但属于同一名称空间.

Both ClassA and Functions are in separate class files but belong to same namespace.

推荐答案

尝试使用

static class ClassA
{
 string temp = Functions.Test();
 public static string Process()
 {
      return temp;
 }
}

static class Functions
{
 public static string Test()
 {
      return "ok";
 }
}

这篇关于当前上下文中不存在名称"temp"(C#桌面应用程序)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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