Skip to content

Commit

Permalink
GH-37359: [C#] Add ToList() to Decimal128Array and Decimal256Array (#…
Browse files Browse the repository at this point in the history
…37383)

Add `ToList()` methods to `Decimal128Array` and `Decimal256Array`.

* Closes: #37359

Authored-by: Danyaal Khan <danyaal99@hotmail.co.uk>
Signed-off-by: Curt Hagenlocher <curt@hagenlocher.org>
  • Loading branch information
DanTm99 committed Dec 4, 2023
1 parent f7947cc commit d357d2d
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 0 deletions.
24 changes: 24 additions & 0 deletions csharp/src/Apache.Arrow/Arrays/Decimal128Array.cs
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,30 @@ public Decimal128Array(ArrayData data)
return DecimalUtility.GetDecimal(ValueBuffer, index, Scale, ByteWidth);
}

public IList<decimal?> ToList(bool includeNulls = false)
{
var list = new List<decimal?>(Length);

for (int i = 0; i < Length; i++)
{
decimal? value = GetValue(i);

if (value.HasValue)
{
list.Add(value.Value);
}
else
{
if (includeNulls)
{
list.Add(null);
}
}
}

return list;
}

public string GetString(int index)
{
if (IsNull(index))
Expand Down
24 changes: 24 additions & 0 deletions csharp/src/Apache.Arrow/Arrays/Decimal256Array.cs
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,30 @@ public Decimal256Array(ArrayData data)
return DecimalUtility.GetDecimal(ValueBuffer, index, Scale, ByteWidth);
}

public IList<decimal?> ToList(bool includeNulls = false)
{
var list = new List<decimal?>(Length);

for (int i = 0; i < Length; i++)
{
decimal? value = GetValue(i);

if (value.HasValue)
{
list.Add(value.Value);
}
else
{
if (includeNulls)
{
list.Add(null);
}
}
}

return list;
}

public string GetString(int index)
{
if (IsNull(index))
Expand Down

0 comments on commit d357d2d

Please sign in to comment.