kruegerste
asked on
C# Generic Method Parameter
Hello,
Is there a way to make the method below generic?
CustomerData is a strongly-typed dataset. I would like to be able to somehow pass a generic strongly-typed dataset in as a parameter or however this can be done so that we only use one method for all instances. Otherwise we will need to duplicate this method about 10 times with different dataset types.
We would also pass in the table name as string for the dataset.
Thanks.
Is there a way to make the method below generic?
CustomerData is a strongly-typed dataset. I would like to be able to somehow pass a generic strongly-typed dataset in as a parameter or however this can be done so that we only use one method for all instances. Otherwise we will need to duplicate this method about 10 times with different dataset types.
We would also pass in the table name as string for the dataset.
Thanks.
public string[] GetCustomerSuggestionList(string columnName, string prefix, int count)
{
CustomerData customerData = new CustomerData();
customerData = GetCustomersAll();
EnumerableRowCollection<DataRow> query = from customer in customerData.Tables["customer"].AsEnumerable()
where customer.Field<string>(columnName) != null && customer.Field<string>(columnName).ToLower().StartsWith(prefix.ToLower())
select customer;
UtilityBF utilityBF = new UtilityBF();
return utilityBF.GetDistinctQueryItems(query, columnName, count);
}
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thanks. I was missing the where statement.
NP. Glad to help :)
Open in new window