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 357815
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T12:14:27+00:00 2026-05-12T12:14:27+00:00

I have created a public static class utils.cs I want to use it in

  • 0

I have created a public static class utils.cs I want to use it in other classes without prefixing method with utils, what’s the syntax to do this ?

  • 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-12T12:14:28+00:00Added an answer on May 12, 2026 at 12:14 pm

    What Jon Skeet is not telling you is that you can have global static members in c#. Your utility class can indeed become a reality in c#.

    Unfortunately, Microsoft has determined that the very process of constructing such members as above mere “normal” development, and requires that you forge them from raw intermediate language. Such a powerful pattern is above common syntax highlighting and friendly icons).

    Here is the requisite sequence of utf-8 characters (guard it carefully):

    .assembly globalmethods {}
    
    .method static public void MyUtilMethod() il managed 
    {
      ldstr "Behold, a global method!"
      call void [mscorlib]System.Console::WriteLine(class System.String) 
      ret
    }
    

    (You could compile this example by invoking ilasm.exe from the SDK command prompt, remembering to use the /dll switch)


    ilasm.exe output:

    Microsoft (R) .NET Framework IL Assembler. Version 2.0.50727.4016
    Copyright (c) Microsoft Corporation. All rights reserved.
    Assembling ‘globalmethods.msil’ to DLL –> ‘globalmethods.dll’
    Source file is ANSI

    global.msil(7) : warning — Reference to undeclared extern assembly ‘mscorlib’.
    Attempting autodetect

    Assembled global method MyUtilMethod

    Creating PE file

    Emitting classes:

    Emitting fields and methods:
    Global Methods: 1;

    Emitting events and properties:
    Global
    Writing PE file
    Operation completed successfully


    Once you have compiled your newly created assembly (as “globalmethods.dll” for example), it’s just a matter of adding a reference in Visual Studio. When that is complete, you better be sitting down, because it will be time to write some real code:

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.Reflection;
    
    namespace TestGlobalMethod
    {
        class Program
        {
            static void Main(string[] args)
            {
    
                "MyUtilMethod".Call();
    
                Console.ReadKey();
    
            }
    
        }
    
        /// <summary>
        /// Reduces the amount of code for global call
        /// </summary>
        public static class GlobalExtensionMethods 
        {
            public static void Call(this string GlobalMethodName)
            {
                Assembly.Load("globalmethods")
                    .GetLoadedModules()[0].GetMethod(GlobalMethodName)
                        .Invoke(null,null);
    
            }
    
        }
    
    
    }
    

    Yes, you just called a Global method in c#.

    *Please don’t use this, it’s for example only 🙂 Also, you could probably write your global methods in another language that support them, such as VB.NET.

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

Sidebar

Related Questions

What I have is a class with static properties that I want to use
I have a control that is created like so: public partial class MYControl :
I have created custom result class to serialize json data to xml. I want
I have created a C# class file by using a XSD-file as an input.
I created a class Foo that has the method toArray() that returns an Array<Int>
I trying to extends ObjectProxy class, the reason is because I want to have
class Main { public static void main() { Student one=new Student(); one.setName(firstname); AllStudent all=new
I have created a simple method to retrieve XML output from an HTTPService and
Suppose I have BaseClass with public methods A and B, and I create DerivedClass
Have created a c++ implementation of the Hough transform for detecting lines in images.

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.