I'm learning C# now. Is an Int Array, value type or reference type?

Posted on 2011-10-02
Last Modified: 2012-05-12
I apologize as this is a basic question.

I'd like to know if an Int Array is a value type or a reference type.

I guess programming language doesn't matter, but I use C# now.

Many thanks in advance.
Question by:proglover
    LVL 85

    Accepted Solution

    See "Value Types and Reference Types":

    Under "Reference Types":

        "All arrays, even if their elements are value types"

    So an int is a value type, but an array of int is a reference type.
    LVL 11

    Assisted Solution

    Also, you can tell C# to treat a value as a reference by using the ref keyword.

            private void Example()
                int i = 5;
                int j = i; // i is still 5 at this point
                ChangeRef(ref i);
                int k = i; // now i is 6

            private void ChangeValue(int i)
                i = 6;

            private void ChangeRef(ref int i)
                i = 6;
    LVL 74

    Assisted Solution

    by:käµfm³d 👽
    Also, you can tell C# to treat a value as a reference by using the ref keyword.
    That's a tad misleading because the same can be said of out  = )

    Author Closing Comment

    Thanks so much for the replies, Idle_Mind, MajorBigDeal and kaufmed.

    I highly appreciate your time..

    Featured Post

    Live: Real-Time Solutions, Start Here

    Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

    Join & Write a Comment

    How to remove superseded packages in windows w60 or w61 installation media (.wim) or online system to prevent unnecessary space. w60 means Windows Vista or Windows Server 2008. w61 means Windows 7 or Windows Server 2008 R2. There are various …
    It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
    This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.
    The viewer will be introduced to the member functions push_back and pop_back of the vector class. The video will teach the difference between the two as well as how to use each one along with its functionality.

    734 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    21 Experts available now in Live!

    Get 1:1 Help Now