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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T23:29:08+00:00 2026-06-04T23:29:08+00:00

i have an array and want to create two classes that contains the reference

  • 0

i have an array and want to create two classes that contains the reference of this array. When i change value of an element in array, i want to see the change in classes. The reason why i want to do that is i have a array of something and i have many classes that should contain or reach this array. How can i do that?

In C, i put the pointer of the array in existing structs and solve the problem but how can i do that in C#? There is no array pointer afaik.

int CommonArray[2] = {1, 2};

struct
{
    int a;
    int *CommonArray;
}S1;

struct
{
    int b;
    int *CommonArray;
}S2;

S1.CommonArray = &CommonArray[0];
S2.CommonArray = &CommonArray[0];

Thank you.

  • 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-04T23:29:10+00:00Added an answer on June 4, 2026 at 11:29 pm

    All arrays are reference types in C#, even if the element type of the array is a value type. So this will be fine:

    public class Foo {
        private readonly int[] array;
    
        public Foo(int[] array) {
            this.array = array;
        }
    
        // Code which uses the array
    }
    
    // This is just a copy of Foo. You could also demonstrate this by
    // creating two separate instances of Foo which happen to refer to the same array
    public class Bar {
        private readonly int[] array;
    
        public Bar(int[] array) {
            this.array = array;
        }
    
        // Code which uses the array
    }
    
    ...
    
    int[] array = { 10, 20 };
    Foo foo = new Foo(array);
    Bar bar = new Bar(array);
    
    // Any changes to the contents of array will be "seen" via the array
    // references in foo and bar
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

i want to create a simple program that i have a array of strings
I have an array that I want to sort based on the value of
I have an array of two dimensional Arrays. I want to create a new
I want to create a dynamic array that will look like this, using years:
I have an array that contains entries that themselves contain two types of entries.
Consider I have an array of elements out of which I want to create
Hi I want to create a JSON array. I have tried using: JSONArray jArray
I have a string $string = 'S:1,M:1,L:1,XL:1,XXL:1,3XL:1'; I want to create an array where
i have two array and i want to make unique array with single array
I have an array that I want on multiple pages, so I made it

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.