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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T21:53:01+00:00 2026-06-16T21:53:01+00:00

I’m attempting to set a private field of an array of ints from outside

  • 0

I’m attempting to set a private field of an array of ints from outside the class through a public property accessor. I’m almost certain the problem is my lack of knowledge of the syntax to get this done. I’ve figured out how to set individual values if I specify the index for the array when accessing the property through the object. Here is what I have so far.

My class below.

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

namespace paramRefVal
{
    class ParamaterTest
    {
        private int[] _ints = new int[5];
        private int _i;

        public int[] Ints
        {
            get { return _ints; }
            set { _ints = value; }
        }

        public int I
        {
            get { return _i; }
            set { _i = value; }
        }

        public void SomeFunction(int[] Ints, int I)
        {
            Ints[0] = 100;
            I = 100;
        }
    }
}

This is my main method

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

namespace paramRefVal
{
    class Program
    {
        static void Main(string[] args)
        {
            ParamaterTest paramTest = new ParamaterTest();
            paramTest.I = 0;
            paramTest.Ints[0] = 99;
            Console.WriteLine("Ints[0] = {0}", paramTest.Ints[0]);
            Console.WriteLine("I = {0}", paramTest.I);
            Console.WriteLine("Calling SomeFunction...");
            paramTest.SomeFunction(paramTest.Ints, paramTest.I);
            Console.WriteLine("Ints[0] = {0}", paramTest.Ints[0]);
            Console.WriteLine("I = {0}", paramTest.I);
            Console.ReadLine();
        }
    }
}

The line I’m interested in is

paramTest.Ints[0] = 99;

I’ve attempted to set multiple values like so to no avail.

paramTest.Ints[] = { 0, 1, 2, 3, 4 };

I’m getting two compilation errors. “The type or namespace name ‘paramTest’ could not be found (are you missing a using directive or an assembly reference?)” without the quotes.

And secondly. “Identifier expected” without the quotes.

Thanks for any help!

  • 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-16T21:53:02+00:00Added an answer on June 16, 2026 at 9:53 pm

    You can use:

    paramTest.Ints = new int[] { 0, 1, 2, 3, 4 };
    

    Which can be simplified to:

    paramTest.Ints = new[] { 0, 1, 2, 3, 4 };
    

    If you want to use the array initializer, you can do it this way:

    int[] ints = {0, 1, 2, 3, 4};
    paramTest.Ints = ints;
    

    I don’t get any compilation error about the type, though. Could you be more specific?

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

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
For some reason, after submitting a string like this Jack’s Spindle from a text
I am confused How to use looping for Json response Array in another Array.
I am trying to find ID3V2 tags from MP3 file using jid3lib in Java.
I am doing a simple coin flipping experiment for class that involves flipping a
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I have an array which has BIG numbers and small numbers in it. I
I have a text area in my form which accepts all possible characters from
I'm trying to convert HTML to plain text. I get many &\#8217; &\#8220; etc.
Does anyone know how can I replace this 2 symbol below from the string

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.