Steps for conversion

Thank you for reading this post, don't forget to subscribe!

Step 1:
//Create structure or class for hold data
public struct GetUserInformation
{
public int UserId { get; set; }
public string UserName { get; set; }
public string FirstName { get; set; }
public string LastName { get; set; }
public string Email { get; set; }
public bool Approved { get; set; }

}

Step 2 :

public DataTable ToDataTable<GetUserInformation>(IList<GetUserInformation> data)
{
PropertyDescriptorCollection props =
TypeDescriptor.GetProperties(typeof(GetUserInformation));
DataTable table = new DataTable();
for (int i = 0; i < props.Count; i++)
{
PropertyDescriptor prop = props[i];
table.Columns.Add(prop.Name, prop.PropertyType);
}
object[] values = new object[props.Count];
foreach (GetUserInformation item in data)
{
for (int i = 0; i < values.Length; i++)
{
values[i] = props[i].GetValue(item);
}
table.Rows.Add(values);
}
return table;
}

    
Step 3:

RoleController objRoleCont = new RoleController();
ArrayList arrayObj = objRoleCont.GetUsersByRoleName();
List<GetUserInformation> obj = new List<GetUserInformation>();

foreach (UserInfo obUser in arrayObj)
{
obj.Add(new GetUserInformation()
{
UserId = obUser.UserID,
UserName = obUser.Username,
FirstName = obUser.FirstName,
LastName = obUser.LastName,
Email = obUser.Email,
Approved = obUser.Approved
});

}

DataTable dt = ToDataTable<GetUserInformation>(obj);