system.array

Aggregate and ToArray function in System.Array not working

≡放荡痞女 提交于 2021-02-17 05:24:09
问题 I have this two errors: 'System.Array' does not contain a definition for 'Aggregate' and no extension method 'Aggregate' accepting a first argument of type 'System.Array' could be found (are you missing a using directive or an assembly reference?) 'System.Collections.Generic.IEnumerable<object[]>' does not contain a definition for 'ToArray' and no extension method 'ToArray' accepting a first argument of type 'System.Collections.Generic.IEnumerable<object[]>' could be found (are you missing a

Why are most methods of System.Array static? [closed]

元气小坏坏 提交于 2020-03-15 18:00:13
问题 As it currently stands, this question is not a good fit for our Q&A format. We expect answers to be supported by facts, references, or expertise, but this question will likely solicit debate, arguments, polling, or extended discussion. If you feel that this question can be improved and possibly reopened, visit the help center for guidance. Closed 6 years ago . 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

Why are most methods of System.Array static? [closed]

旧巷老猫 提交于 2020-03-15 17:58:13
问题 As it currently stands, this question is not a good fit for our Q&A format. We expect answers to be supported by facts, references, or expertise, but this question will likely solicit debate, arguments, polling, or extended discussion. If you feel that this question can be improved and possibly reopened, visit the help center for guidance. Closed 6 years ago . 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

Why are most methods of System.Array static? [closed]

ぐ巨炮叔叔 提交于 2020-03-15 17:56:38
问题 As it currently stands, this question is not a good fit for our Q&A format. We expect answers to be supported by facts, references, or expertise, but this question will likely solicit debate, arguments, polling, or extended discussion. If you feel that this question can be improved and possibly reopened, visit the help center for guidance. Closed 6 years ago . 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

Why System.Array class implements IList but does not provide Add()

不羁的心 提交于 2019-12-18 20:46:03
问题 This code: int[] myArr = { 1, 2 }; myArr.Add(3); throws 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 found (are you missing a using directive or an assembly reference?) IList interface has the Add() method, but why the Array does not implement it? UPDATE : I see from the answers that it DOES implement it explicitly, OK, I get it, thank you, I should better stick to the

Marshalling System.Array from .Net to vb6

守給你的承諾、 提交于 2019-12-10 22:39:59
问题 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 as string[] and it will be fine, but my question is for particularly when it returns System.Array. So for simplicity the .Net method is the following: public Array GetData() { return new string[] { }; } Then in the VB6 project no matter how I try I

Get the type of an array object [duplicate]

拈花ヽ惹草 提交于 2019-12-08 06:46:23
问题 This question already has an answer here : Closed 7 years ago . Possible Duplicate: How do I use reflection to determine the nested type of an array? I have a class A and trying to get the underlying type of an array in it. Class A { A1[] obja1; A2[] obja2; string x; int i; } How do I get the underlying object type of obja1 as A1 and obja2 as A2?Here is the part of the code I have: object AClass = myAssembly.CreateInstance("A"); PropertyInfo[] pinfos = AClass.GetType().GetProperties();

C# loop over an array of unknown dimensions

风流意气都作罢 提交于 2019-12-01 10:43:02
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<T>(this Array source, Action<T> action) { if(source.Rank == 1) { for (int w = 0; w < source.GetLength(0); w++) { action((T)source.GetValue(w)); } } else if(source.Rank == 2) { for (int h = 0; h < source.GetLength(1); h++) { for (int w = 0; w < source.GetLength(0); w++) { action((T)source.GetValue(h, w)); } } } else if(source.Rank == 3) { // etc } } I am sure, there is much more elegant way of doing that. But I can not figure it out.

C# loop over an array of unknown dimensions

早过忘川 提交于 2019-12-01 09:29:00
问题 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<T>(this Array source, Action<T> action) { if(source.Rank == 1) { for (int w = 0; w < source.GetLength(0); w++) { action((T)source.GetValue(w)); } } else if(source.Rank == 2) { for (int h = 0; h < source.GetLength(1); h++) { for (int w = 0; w < source.GetLength(0); w++) { action((T)source.GetValue(h, w)); } } } else if(source.Rank == 3

Convert System.Array to string[]

元气小坏坏 提交于 2019-11-28 06:44:09
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 elements until runtime. How about using LINQ? string[] foo = someObjectArray.OfType<object>().Select(o => o.ToString()).ToArray(); Is it just Array ? Or is it (for example) object[] ? If so: object[] arr = ... string[] strings = Array.ConvertAll<object, string>(arr, Convert.ToString); Note than any 1-d array of reference-types should be castable to