Question:
I'm learning C# now. Is an Int Array, value type or reference type?
James
2011-10-02 10:12:24 UTC
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.
Three answers:
Jeremy W
2011-10-02 11:10:01 UTC
An int array is a reference type; don't confuse Integers with int though, Integer is a wrapper class for int; because Integer is not a primitive type, it is thus a reference type(opposed to int which is a value type.) In the case of arrays, it is a reference type. The below snippet illustrates this:



int[] arr = new int[] {1, 2, 3, 4};

int[] arr2 = arr;

arr2[1] = 9;



alert(arr[1]);
Me M
2011-10-02 10:58:25 UTC
In C# arrays are reference types.



Since you are just learning the language I will make two suggestions.

First, Microsoft's MSDN site is very thorough in giving examples and explaining various aspects of their programming languages and the .NET libraries. Learn to search the MSDN library to get info on these types of questions.



Second, for simple questions like this, it is best to test the problem yourself. You are more likely to remember it if you wrote code to test it and you will get your answer more quickly than you will if you have to wait for a response on a message board. When learning a new language, I usually create one new project that has no purpose other than to test small questions like this. I keep the code simple and just erase/rewrite the code in this one project every time I have a new thing to test. Try it. You could test this question in about 15 lines of code.
?
2016-12-03 02:43:17 UTC
bool equipment.Boolean byte equipment.Byte sbyte equipment.SByte char equipment.Char decimal equipment.Decimal double equipment.Double drift equipment.single int equipment.Int32 uint equipment.UInt32 long equipment.Int64 ulong equipment.UInt64 merchandise equipment.merchandise short equipment.Int16 ushort equipment.UInt16 string equipment.String use the article browser in seen studio to locate extra training approximately them


This content was originally posted on Y! Answers, a Q&A website that shut down in 2021.
Loading...