-
Notifications
You must be signed in to change notification settings - Fork 8
Flat elements
zmjack edited this page Jun 12, 2023
·
1 revision
Creates a one-dimensional enumeration containing all elements of the specified multidimensional arrays.
Example 1 ( Flat multidimensional array )
var d2 = new string[2, 2]
{
{ "0", "1" },
{ "2", "3" }
};
Console.WriteLine(
Any.Flat<string>(d2).Join(", ")
);
0, 1, 2, 3
Example 2 ( Flat jagged array )
var d1_d1 = new string[2][]
{
new string[] { "0", "1" },
new string[] { "2", "3" },
};
Console.WriteLine(
Any.Flat<string>(d1_d1).Join(", ")
);
0, 1, 2, 3
Example 3(Flat jagged multidimensional array)
var d1_d2 = new string[2][,]
{
new string[2, 2]
{
{ "0", "1" },
{ "2", "3" }
},
new string[2, 2]
{
{ "4", "5" },
{ "6", "7" }
},
};
Console.WriteLine(
Any.Flat<string>(d1_d2).Join(", ")
);
0, 1, 2, 3, 4, 5, 6, 7
Example 4 ( Flat nested array )
var array = new object[2]
{
new string[2] { "0", "1" },
new object[2]
{
"2",
new string[2]
{
"3", "4"
}
}
};
Console.WriteLine(
Any.Flat<string>(array).Join(", ")
);
0, 1, 2, 3, 4
Example 5 ( Flat unmanaged multidimensional array )
var d2 = new int[2, 2]
{
{ 0, 1 },
{ 2, 3 }
};
var length = d2.GetSequenceLength();
fixed (int* pd2 = d2)
{
Console.WriteLine(
Any.Flat(pd2, length).Join(", ")
);
}
0, 1, 2, 3
Example 6 ( Flat unmanaged jagged array )
var d1_d1 = new int[2][]
{
new int[] { 0, 1 },
new int[] { 2, 3 },
};
var lengths = d1_d1.Select(x => x.GetSequenceLength()).ToArray();
fixed (int* pd0 = d1_d1[0])
fixed (int* pd1 = d1_d1[1])
{
Console.WriteLine(
Any.Flat(new[] { pd0, pd1 }, lengths).Join(", ")
);
}
0, 1, 2, 3
var numbers = new[]
{
new[] { 1, 2, 3 },
new[] { 4, 5, 6 },
new[] { 7, 8, 9 },
};
Console.WriteLine(
Any.Flat<int>(numbers).Sum(x => x)
);
45
English | 中文 |
- Array initialization
- Array mapping
- Array reallocation
- Chain loop
- Compose / Pipeline
- Date & Time
- Flat elements
- Index-Value Pairs
- Traverse by depth
- Zip sequences
- [Come soon] Counter
- DP container
- Evaluator
- Fixed size queue
- Scope
- Sequence input stream
- Sliding
- State
- Value with unit
- Variant string