when I change a value in one variable, it is also changed in another.

zequion 446 Reputation points
2023-08-16T02:49:00.0766667+00:00

VS 17.7.2 with .Net framework 4.8.1

I assign an int[] to a dynamic or another int[] and when I change an index in any of the 2 it is also changed in the other.

https://youtu.be/Dzy6ZY8Y22U

https://youtu.be/UDs1jHX3TfI

Developer technologies | .NET | Other
Developer technologies | C#
0 comments No comments
{count} votes

Accepted answer
  1. Minxin Yu 13,501 Reputation points Microsoft External Staff
    2023-08-16T03:22:13.1833333+00:00

    Hi, @zequion

    int[] is array types.

    Arrays (C# Programming Guide)

    Array types are reference types derived from the abstract base type Array.

    In C# array is reference type.

    Reference types

    operations on one variable can affect the object referenced by the other variable

    Best regards,

    Minxin Yu


    If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".

    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.


0 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.