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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T06:36:55+00:00 2026-05-26T06:36:55+00:00

I have a C# code like this: using System; delegate int anto(int x); class

  • 0

I have a C# code like this:

using System;
delegate int anto(int x);
class Anto 
{
    static void Main()
    {
        anto a = square;
        int result = a(3);
        Console.WriteLine(result);
    }
    static int square(int x)
    {
        return x*x;
    }
}

which output’s : 9. Well I’m a novice in C#, so I started to play around with this code and so when I remove the static keyword from the square method, then I’m getting error like this:

An object reference is required to access non-static member `Anto.square(int)'
Compilation failed: 1 error(s), 0 warnings

what causes this error? So if I use delegates I need the method to be static?

I run this code here

Thanks in advance.

  • 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-26T06:36:55+00:00Added an answer on May 26, 2026 at 6:36 am

    Because Main is static, it can only reference other static members. If you remove static from square, it becomes an instance member, and in the static context of Main, there is no instance of any object, so instance members aren’t ‘valid’.

    Thankfully there’s nothing crazy going on with delegates, it’s just the way static works – it indicates members are global to a type and not an instance of that type.

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

Sidebar

Related Questions

I'm using boost::asio, and I have code like this: void CServer::Start(int port) { tcp::acceptor
I have a class that creates and uses a System.Threading.Timer, something like this: using
I have problem installing simple Windows Service, my code looks like this: using System;
I have an asynchronous socket listener class like this: using System; using System.Collections.Generic; using
I have a page, Default.aspx, with its own code-behind file like this: using System;
In many places in our application we have code like this: using(RAPI rapi =
I have a code that looks like this: using (DC dc = new DC())
Using dotnet 2.0. I currently have code like this : DataView dv = new
I'm using PHP5 to create XML files. I have code like this: $doc =
Let's say I have some code (using CherryPy) that looks like this: import cherrypy

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.