项目作者: jonasraoni

项目描述 :
C# extension method to flatten N-dimensional arrays of any data type.
高级语言: C#
项目地址: git://github.com/jonasraoni/flatten-array.git
创建时间: 2018-08-06T19:52:34Z
项目社区:https://github.com/jonasraoni/flatten-array

开源协议:

下载


Flatten Array

C# extension method to flatten N-dimensional arrays of any data type.

Samples

  1. var intArray = new[, ,] { { { 1, 1 }, { 2, 3 } } };
  2. CollectionAssert.AreEqual(intArray.Flatten<int>(), new[] { 1, 1, 2, 3 });
  3. var dynamicJaggedArray = new dynamic[] { 1, new dynamic[] { "2", 3, new { prop = 123 } } };
  4. CollectionAssert.AreEqual(dynamicJaggedArray.Flatten<dynamic>(), new dynamic[] { 1, "2", 3, new { prop = 123 } });
  5. var intJaggedArray = new int[][] { new int[] { 1, 1 }, new int[] { 2, 3, 4 } };
  6. CollectionAssert.AreEqual(intJaggedArray.Flatten<int>(), new[] { 1, 1, 2, 3, 4 });
  7. var stringJaggedArray = new dynamic[] { new[] { "a" }, new dynamic[] { "b", new[] { "c" } } };
  8. CollectionAssert.AreEqual(stringJaggedArray.Flatten<string>(), new[] { "a", "b", "c" });

Considerations

  • Developed using Visual Studio Community and .NET Framework 4.7.1.
  • Compatible with all types of arrays.
  • Generics was used only to define the return type.
  • Unit testing done through MSTest.