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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T15:24:48+00:00 2026-05-30T15:24:48+00:00

Hello everyone I am trying to make since of what I am doing wrong

  • 0

Hello everyone I am trying to make since of what I am doing wrong or maybe I am over thinking it again. I am trying to create a class and in the class I am calling 2 private variables such as num1 and num2. Then i create a public property that corresponds to num 1 and num2. Then after I create that I need to create a public overriable method called calculate and this will add the two variables together and returns the results. Then I have a add button that I have to add the code to the button that adds the two numbers and output the result to a messagebox.I have tried a couple different ways and I still am not getting it.
Here is code 1:

 public abstract class CalulateValues
{
    protected List<int> values = new List<int>();
    public void AddValue(int value) { values.Add(value); }
    public abstract int Calculate();

}

public class Add : CalulateValues
{
    public override int Calculate()
    {
        return values.Sum(x => x);
    }
}

and here is code 2 I tried:

class CalculateValues
{
    private int _num1;
    private int _num2;


    public int Num1
    {
        get
        {
            return _num1;
        }
        set
        {
            _num1 = value;
        }
    }
    public int Num2
    {
        get
        {
            return _num2;
        }
        set
        {
            _num2 = value;
        }
    }
    public virtual int calculate()
    {
        return _num1 + _num2;

    }
}

Now when it comes with the button I have tried this code:

public partial class Form2 : Form
{
    public Form2()
    {
        CalculateValues myAdd = new CalculateValues();
        MulitplyValues Add = new MulitplyValues();
        InitializeComponent();
    }

    private void button1_Click(object sender, EventArgs e)
    {

        int total = myAdd.Add(int.Parse(textBox1.Text), int.Parse(textBox2.Text));    
        MessageBox.Show(total.ToString());

    }

I am not too sure what I am doing wrong maybe I am not laying out the code the right way.

  • 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-30T15:24:50+00:00Added an answer on May 30, 2026 at 3:24 pm

    You have declared myAdd as a local variable in the Form2 constructor. Declare it as a global variable in order to be able to call it from button1_Click()

    In addition to this, are you getting any error or exception? Second, where did you declare Add method that accepts two parameters?

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

Sidebar

Related Questions

hello everyone I am trying to make a script that steps through a list
Hello everyone. I am trying to play a bit with RSA public and private
Hello everyone i need some help. I'm trying to make an application for mac
hello everyone im trying to create this tweak that copies a file from one
Hello everyone I have a question... I'm trying to make my sms faker app,
Hello everyone I'm trying to make a jquery Menu just like the one in
Hello everyone I am trying to make a gallery on my website and I
Hello everyone I'm currently trying to create a deferred renderer for my graphics engine
Hello there everyone, I've been trying to figure out how to create a function
Hello everyone I'm trying to make a flash uploader. The issue however that has

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.