Search code examples
c#static-classes

The name 'temp' does not exist in the current context (C# desktop application)


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";
     }
}

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"

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


Solution

  • try with

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