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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T22:21:19+00:00 2026-06-01T22:21:19+00:00

I need help with C# programming; I am new to it and I come

  • 0

I need help with C# programming; I am new to it and I come from C background. I have a Console Application like this:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Add_Function
{
   class Program
   {
      static void Main(string[] args)
      {
         int a;
         int b;
         int c;

         Console.WriteLine("Enter value of 'a':");
         a = Convert.ToInt32(Console.ReadLine());

         Console.WriteLine("Enter value of 'b':");
         b = Convert.ToInt32(Console.ReadLine());

         //why can't I not use it this way?
         c = Add(a, b);
         Console.WriteLine("a + b = {0}", c);
      }//END   Main

      public int Add(int x, int y)
      { 
         int result = x + y;
         return result;
      }//END   Add
   }//END      Program
}//END         Add_Function

It gives me this error on the line that I call Add():

An object reference is required for the non-static field, method, or property ‘Add_Function.Program.Add(int, int)’

Can anyone please explain to me why I have this problem. Is this because the architecture of C# is different than C, and the way I call it is wrong? Thanks.

  • 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-01T22:21:21+00:00Added an answer on June 1, 2026 at 10:21 pm

    Note: in C# the term “function” is often replaced by the term “method”. For the sake of this question there is no difference, so I’ll just use the term “function”.

    The other answers have already given you a quick way to fix your problem (just make Add a static function), but I’d like to explain why.

    C# has a fundamentally different design paradigm than C. That paradigm is called object-oriented programming (OOP). Explaining all the differences between OOP and functional programming is beyond the scope of this question, but here’s the short version as it applies to you.

    Writing your program in C, you would have created a function that adds two numbers, and that function would exist independently and be callable from anywhere. In C# most functions don’t exist independently; instead, they exist in the context of an object. In your example code, only an instance (an object) of the class Program knows how to perform Add. Said another way, you have to create an instance of Program, and then ask Program to perform an Add for you.

    The solutions that people gave you, using the static keyword, route around that design. Using the static keyword is kind of like saying, “Hey, this function I’m defining doesn’t need any context/state, it can just be called.” Since your Add function is very simple, this makes sense. As you start diving deeper into OOP, you’re going to find that your functions get more complicated and rely on knowing their state/context.

    My advice: Pick up an OOP book and get ready to switch your brain from functional programming to OOP programming. You’re in for a ride.

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

Sidebar

Related Questions

I come from a procedural programming background, and need some help grasping how methods
I really need your help for this. I am relatively new to programming and
Need help writing a script downloads data from google insight using c# this is
I'm new programming in shell and I need some help with this code... Buildname=
I'm (very) new to all of this programming stuff and I need help with
I'm kinda new to programming and need help doing a recursive method.I have a
i am new to programming and i need your help... i have a label
I am new to bash/awk programming and need your help soon This is hexadecimal
I am new to this shell-script programming so need your help to write a
i am new to iOS programming. i really need your help. i have a

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.