S
Stuart Shay
Hello All
I have the following LINQ Query in which I only want to return a single
column in the results as a String Array is there a way dyamically change in
the column name.
var expr = from usr in usertList
select new UserAdministrationModel
{
UserName = usr.UserName,
Email = usr.Email
};
//Hardcoded Test Value
string columnName = "Email";
System.Collections.Generic.List<string> items = new
System.Collections.Generic.List<string>();
foreach (var model in expr)
{
if(columnName == "UserName")
items.Add(model.UserName);
else if(columnName == "Email")
items.Add(model.Email);
}
return items.ToArray();
I have the following LINQ Query in which I only want to return a single
column in the results as a String Array is there a way dyamically change in
the column name.
var expr = from usr in usertList
select new UserAdministrationModel
{
UserName = usr.UserName,
Email = usr.Email
};
//Hardcoded Test Value
string columnName = "Email";
System.Collections.Generic.List<string> items = new
System.Collections.Generic.List<string>();
foreach (var model in expr)
{
if(columnName == "UserName")
items.Add(model.UserName);
else if(columnName == "Email")
items.Add(model.Email);
}
return items.ToArray();