Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Convert a BindingList<T> to an array of T

What's the easiest way to convert a BindingList<T> to a T[] ?

EDIT: I'm on 3.0 for this project, so no LINQ.

like image 951
Gerrie Schenck Avatar asked Jan 26 '26 21:01

Gerrie Schenck


2 Answers

Well, if you have LINQ (C# 3.0 + either .NET 3.5 or LINQBridge) you can use .ToArray() - otherwise, just create an array and copy the data.

T[] arr = new T[list.Count];
list.CopyTo(arr, 0);
like image 182
Marc Gravell Avatar answered Jan 29 '26 11:01

Marc Gravell


In .Net 2 you have to use .CopyTo() method on your BindingList<T>

like image 31
Grzenio Avatar answered Jan 29 '26 11:01

Grzenio



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!