Skip to content

Commit

Permalink
apacheGH-37359: [C#] Add ToList() to Decimal128Array and Decimal256Array
Browse files Browse the repository at this point in the history
  • Loading branch information
DanTm99 committed Aug 25, 2023
1 parent b9453a2 commit 241a57d
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 @@ -91,5 +91,29 @@ 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;
}
}
}
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 @@ -92,5 +92,29 @@ 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;
}
}
}

0 comments on commit 241a57d

Please sign in to comment.