Muhammad Alaa
Muhammad Alaa

Reputation: 245

insert object in selected linq array

I implemented the following method to get array of departments to bind to dropdownlist

public object[] GetDepartmentOptions()
{
   var departments = from p in context.per_Departments
                     where p.active == true
                     select new { DisplayText = p.departmentNameEn, 
                                  Value = p.departmentId };
   return departments.ToArray();
}

I would like to insert object in this array before bind it

object =new { DisplayText = "Choose", Value = 0 };

Upvotes: 0

Views: 109

Answers (1)

Laszlo Boke
Laszlo Boke

Reputation: 1329

For some reason it works only if your first sequence is the "choose" sequence:

    var first = new[] { new { DisplayText = "Choose", Value = 0 } };
    return first.Concat(departments).ToArray();

Upvotes: 2

Related Questions