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

  • Home
  • SEARCH
  • 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 981943
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T04:37:18+00:00 2026-05-16T04:37:18+00:00

I have a function in a utility class namespace GUI.code { public class Utility

  • 0

I have a function in a utility class

  namespace GUI.code
 {
   public class Utility
  {
     public string GetFileName(string grpID)
    {
        string filenameUNC = "\\\\" + "localhost" + "\\AgentShare\\";

        string realPath = GetPath(filenameUNC);

        return realPath;
    }
   }
  }

now i call this function from another page in the project like this:

new utility.GetCSFileName(ID);

why do i need to add new, why cant i call it like

GetCSFileName(ID);

when i have

     using GUI.code;

on top

if i remove new i get this error

Error 1 An object reference is required for the non-static field, method, or property ‘copiunGUI.code.GUIUtility.GetCSFileName(string)

any suggestions

  • 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-05-16T04:37:19+00:00Added an answer on May 16, 2026 at 4:37 am

    You can call Utility.GetFileName() if you change the declaration to public static string GetFileName(string grpID)

    static means that the member is shared among all instances of the Utility class. Remember, c# is an object-oriented language. Non-static members are called instance members, and must be called on a distinct instance of the class. Each time you call new Utility(), you are creating such an instance, and this is distinct from every other.

    This is useful when each instance of a class needs to maintain information (state) internally. If, however, a particular member does not use state data — it accepts parameters, does work, and optionally returns a result — it can be declared static. Then you call it not from the instance variable but from the class name itself (in this case Utility.GetFileName().

    When all of the members of a class are static, you can add static to the class declaration itself. At that point, you would never be able to call new Utility(), which might be what you want in this case.

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

Sidebar

Related Questions

i have following code #include <iostream> #include <utility> using namespace std; namespace rel_ops{ template<class
Suppose I have a utility function like this - public static boolean isABlankSpace(char c)
I have created an utility function which I include in almost all Javascript code
I have a class Yarl in my code with a member function refresh that
I have the following code. The intent is to have this utility class that
Hello guys I have a function inside a utility class which returns the current
I have a utility function in my program for searching for entities. It takes
i have function public Menu Details(int? id) { return _dataContext.Menu.Include(ChildMenu).FirstOrDefault(m => m.MenuId == id);
Assume I have a class a: class a { public: void load_data( ); private:
I am trying to specialize some utility code on const member functions, but have

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.