I have a class with one public property.
public class CustomEntity
{
string _FileName;
public string FileName
{
get { return _FileName; }
set
{
_FileName = value;
}
}
}
I have array of string which I want to convert in List of "CustomEntity" using linq. please suggest me how I can do that.
I would use Linq's Select extension and ToList to convert the IEnumerable (from Select extension) to a list
An Example:
string[] randomArray = new string[3] {"1", "2", "3"};
List<CustomEntity> listOfEntities = randomArray.Select(item => new CustomEntity() { FileName = item } ).ToList();
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With