Serves as the base class for arrays. Provides methods for creating, copying, manipulating, searching, and sorting arrays.
Questions tagged [system.array]
33 questions
136
votes
13 answers
C# Iterating through an enum? (Indexing a System.Array)
I have the following code:
// Obtain the string names of all the elements within myEnum
String[] names = Enum.GetNames( typeof( myEnum ) );
// Obtain the values of all the elements within myEnum
Array values = Enum.GetValues( typeof( myEnum )…

TK.
- 46,577
- 46
- 119
- 147
48
votes
5 answers
Convert System.Array to string[]
I have a System.Array that I need to convert to string[]. Is there a better way to do this than just looping through the array, calling ToString on each element, and saving to a string[]? The problem is I don't necessarily know the type of the…

KrisTrip
- 4,943
- 12
- 55
- 74
18
votes
1 answer
Why are most methods of System.Array static?
I guess this is more of a framework design question. I recently wondered why most of the methods in System.Array are static. My gut reaction always is to use e.g. IndexOf(object) on the Array instance, not as System.Array.IndexOf(array, object). Is…

needfulthing
- 1,056
- 11
- 21
17
votes
6 answers
casting system.array object to int[] string or other type's objects
I am learning c# and trying to understand the "type oriented" aspects of it.
So the other day I needed to receive an System.Array object from a method.
Then I tried to work with it's individual objects, so i tried to address it with an…

Eliy Arlev
- 511
- 1
- 4
- 14
11
votes
7 answers
Why System.Array class implements IList but does not provide Add()
This code:
int[] myArr = { 1, 2 };
myArr.Add(3);
throws the following error on Build:
error CS1061: 'System.Array' does not contain a definition for 'Add' and no extension method 'Add' accepting a first argument of type 'System.Array' could be…

cnom
- 3,071
- 4
- 30
- 60
8
votes
1 answer
Fastest way to apply arithmetic operations to System.Array in IronPython
I would like to add (arithmetics) two large System.Arrays element-wise in IronPython and store the result in the first array like this:
for i in range(0:ArrA.Count) :
arrA.SetValue(i, arrA.GetValue(i) + arrB.GetValue(i));
However, this…

c_k
- 1,746
- 1
- 20
- 35
7
votes
3 answers
Where can I find information on the Get, Set and Address methods for multidimensional System.Array instances in .NET?
System.Array serves as the base class for all arrays in the Common Language Runtime (CLR). According to this article:
For each concrete array type, [the] runtime adds three special methods: Get/Set/Address.
and indeed if I disassemble this C#…

Rob Smallshire
- 1,450
- 1
- 15
- 22
6
votes
2 answers
Return array of strings from MVC to jQuery ASP.NET
I want to return an array of strings from an MVC function via a jQuery AJAX call.
My client side code is:
function get_categories() {
var url = "/Profile/GetCharacters";
$.post(url, function (data) {
alert(data);
});
But I cannot read…

SkyPunch
- 313
- 1
- 4
- 19
4
votes
2 answers
How to create a reference to System.Array holding strings in C#
I have an interesting question regarding C# code.
Basically I have to call a method
BCI2000AutomationLib.IBCI2000Remote.StartupModules(ref System.Array)
Using Visual Studio 2010 the following code compiles and works perfectly:
// Startup…

pjercic
- 417
- 1
- 7
- 19
3
votes
3 answers
C# loop over an array of unknown dimensions
I want to create an extension method to loop over System.Array with unknown number of dimensions
For now I am using a naive approach:
public static void ForEach(this Array source, Action action)
{
if(source.Rank == 1)
{
for…

koryakinp
- 3,989
- 6
- 26
- 56
3
votes
3 answers
How do you test for null elements in System.Array
I'm parsing an excel document into a System.Array and then using this data to develop a DataTable. The problem is that not every element in the System.Array contains a string and is null. See image below:
My question is how to I test for the null…

Chris
- 934
- 1
- 17
- 38
3
votes
1 answer
Why am I getting "'System.Array' does not contain a definition for 'AsBuffer'" with this WinRT code?
According to this, the following code can be used to convert a byte array into a BitmapImage:
public static async Task ByteArrayToBitmapImage(this byte[] byteArray)
{
if (byteArray != null)
{
using (var stream = new…

B. Clay Shannon-B. Crow Raven
- 8,547
- 144
- 472
- 862
2
votes
1 answer
System.Array.IndexOf allocates memory
I've been profiling my code and found that System.Array.IndexOf is allocating a fair bit of memory. I've been trying to find out how come this happens.
public struct LRItem
{
public ProductionRule Rule { get; } // ProductionRule is a class
…

ikkentim
- 1,639
- 15
- 30
2
votes
3 answers
I don't understand a code to load picture in java
I am working with OpenCV in java, but I don't understand part of a class that loads pictures in java:
public class ImageProcessor {
public BufferedImage toBufferedImage(Mat matrix){
int type = BufferedImage.TYPE_BYTE_GRAY;
if (…

hadis
- 87
- 7
2
votes
2 answers
Marshalling System.Array from .Net to vb6
I have a .Net component that has a COM visible class with a method that returns a System.Array. Under the hood it returns a string array, however the return type is declared as System.Array. Don't ask me "why", I know I can declare the return type…

Tiger Galo
- 289
- 4
- 15