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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T00:54:04+00:00 2026-06-11T00:54:04+00:00

i am trying to compile this code about arrays and classes in visual studio

  • 0

i am trying to compile this code about arrays and classes in visual studio 2010 but i am having problems when running it an error(consoleapplication.Carray does not contain a constructor that takes 0 arguments)is displaying, may someone tell me what wrong i am doing the code only displays and array or is there any way i can do it????
code

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

namespace ConsoleApplication1
{
    class Program
    {
        static void Main()
        {
            CArray CArray;
            CArray nums = new CArray();
            for (int i = 0; i <= 49; i++)
                nums.insert(i);
            nums.displayElements();
        }
    }

    class CArray
    {
        private int[] arr;
        private int upper;
        private int numElements;
        public CArray(int size)
        {
            arr = new int[size];
            upper = size - 1;
            numElements = 0;

        }
        public void insert(int item)
        {
            arr[numElements] = item;
            numElements++;
        }
        public void displayElements()
        {
            for (int i = 0; i <= upper; i++)
                Console.Write(arr[i] + " ");

        }
        public void clear()
        {
            for (int i = 0; i <= upper; i++)
                arr[i] = 0;
            numElements = 0;

        }
    }
}
  • 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-11T00:54:05+00:00Added an answer on June 11, 2026 at 12:54 am

    OK, several problems. One you have a constructor that is requesting the size of the array, and your main program is not feeding that to the constructor. This is also problematic because you are using the size of the array in your displayelements() loop. This won’t compile since your constructor takes an argument. You need to, at the very least, change your Main() program so that it feeds the size of your array to the constructor, which you have defined in your class CArray. Change the following:

                CArray nums = new CArray(50); //since 50 is the length of your array
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to compile the next code, but I'm getting this error on the
I'm reading this post about go and was trying to compile the source code
When trying to compile this code: #include <iostream> #include <vector> using namespace std; class
I trying to compile this code: Int64 itag = BitConverter.ToInt64(temp, 0); itag &= 0xFFFFFFFFFFFFFC00;
When I'm trying to compile this code with gcc version 4.6.3 on linux with
I'm trying to figure out why this code won't compile. I have interface A
I am trying to use some sample code and my compiler won't compile this
I get this error when trying to make the executable, the code compiles correctly
I am trying to get some C++ code originally written in Microsoft Visual Studio
I'm currently trying to compile a PHP driver for MongoDB using Visual Studio 2008

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.