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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T19:47:37+00:00 2026-05-22T19:47:37+00:00

I am trying to code simple membership class. First class name is Customer and

  • 0

I am trying to code simple membership class. First class name is Customer and it has others classes like Silver_Customer, Gold_Customer which are inherited from Customer class.

I use these classes in my simple windows application:

    public Customer customer;
    public Form_MURAT_TURAN()
    {
        InitializeComponent();
    }
    private void Form1_Load(object sender, EventArgs e)
    {
        Product p1 = new Product("Blouse", 152.80);
        Product p2 = new Product("T-Shirt", 50.25);
        .....
        lbProducts.Items.Add(p1);
        lbProducts.Items.Add(p2);
        .....
    }

    private void btnCustomer_Click(object sender, EventArgs e)
    {
        Customer customer = new Standard_Customer(txtName.Text, txtSurname.Text, 0);
        customer.Name = "Mark 1";
        customer.TotalAmount = 5;
        gbCustomer.Enabled = false;
        gbProduct.Enabled = true;

        set_info(customer.customerType(), customer.Name + " " + customer.Surname, customer.TotalAmount);
    }

    private void btnAddToBasket_Click(object sender, EventArgs e)
    {
        customer.Name = "Mark 2";
    }

Everything works fine except btnAddToBasket_Click method. customer.Name = “Mark 2”; line give me NullReferenceException error but customer.Name = “Mark 1” line works.

  • 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-22T19:47:38+00:00Added an answer on May 22, 2026 at 7:47 pm

    In btnCustomer_Click, you are not setting your global customer object. You are setting a local version of it. Change your code as follows:

    private void btnCustomer_Click(object sender, EventArgs e)
    {
        customer = new Standard_Customer(txtName.Text, txtSurname.Text, 0);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to understand this simple hashlib code in Python that has been
i am trying to compile this very simple piece of code class myList {
I am trying to code an simple PHP application which will retrieve some information
I am trying some simple code on fork. When I give code like this,
I'm trying to code a simple base64 encoder/decoder (to test my programming skill). I
I'm trying to send messages generated by Google Protocol Buffer code via a simple
I trying to create a pipe using C#. The code is quite simple but
I am trying to write simple Visual Studio Add-In for code generation. In my
I'm trying to compile the following simple DL library example code from Program-Library-HOWTO with
I am trying to write a simple tool using Shoes. This will indent code

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.