Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8126907
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T07:19:42+00:00 2026-06-06T07:19:42+00:00

I want to use a function from another class within a new function which

  • 0

I want to use a function from another class within a new function which I will call from main. I am trying to do this as below, but get an error:

Error The name ‘Class1’ does not exist in the current context.

Actually, in my code I use different names, but its just to illustrate the structure and to make it easier to read for you.

public class Class1
{      
    public static int[] Function1()
    {
       // code to return value
    }
}


public class Class2
{ 
      public static int Function2()
      {
         int[] Variable = Class1.Function1();
         //other code using function1 value
      }
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-06T07:19:44+00:00Added an answer on June 6, 2026 at 7:19 am

    Actually, in my code I use different names, but its just to illustrate the structure and to make it easier to read for you.

    Unfortunately you’ve made it so easy to read that you have eliminated the problem entirely! The code you posted does not contain an error and is perfectly valid.

    The error message is very clear; from wherever you are actually calling the code, “Class1” (or whatever it may be) is not in scope. This may be because it is in a different namespace. It may also be a simple typo in your class name. Does your code actually look something like this?

    namespace Different 
    {
        public class Class1
        {      
            public static int[] Function1()
            {
               // code to return value
            }
        }
    }
    
    namespace MyNamespace
    {    
        class Program
        { 
              static void Main(string[] args)
              {
                  // Error
                  var arr = Class1.Function();
    
                  // you need to use...
                  var arr = Different.Class1.Function();
              }
        }
    }
    

    That’s the best I got until you post the actual code.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to use gcd function of the Integer class. Using the example from
I'm trying to use .Net serialport methods from another program which uses Unity3D engine.
I want to use a function from my Page class but I do not
I want to use this function EnumWindows(EnumWindowsProc, NULL);. The EnumWindowsProc is a Callback function:
I want to use this function: http://www.frankmacdonald.co.uk/php/post-to-wordpress-with-php.html Its used to post to Wordpress using
I want to encapsulate delegate methods, which will be invoked later on. This delegate
I want use javascript setInterval function to achieve a box rotate animate effect, I
I want to use the function gmp_random() by GNU MP in PHP. I need
i want to use .animate function but i have some problems i want to
I want to use magic function __set() and __get() for storing SQL data inside

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.