Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium


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

Posted on 2011-10-02
Medium Priority
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 86

Accepted Solution

Mike Tomlinson earned 1600 total points
ID: 36899834
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

MajorBigDeal earned 200 total points
ID: 36900089
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 75

Assisted Solution

by:käµfm³d 👽
käµfm³d   👽 earned 200 total points
ID: 36900129
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

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

I highly appreciate your time..

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Having just graduated from college and entered the workforce, I don’t find myself always using the tools and programs I grew accustomed to over the past four years. However, there is one program I continually find myself reverting back to…R.   So …
This article is meant to give a basic understanding of how to use R Sweave as a way to merge LaTeX and R code seamlessly into one presentable document.
This tutorial explains how to use the VisualVM tool for the Java platform application. This video goes into detail on the Threads, Sampler, and Profiler tabs.
The goal of the video will be to teach the user the concept of local variables and scope. An example of a locally defined variable will be given as well as an explanation of what scope is in C++. The local variable and concept of scope will be relat…
Suggested Courses

580 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