1

I have a tool that can automatically generate SQL queries. I am adding a method to create a WHERE clause such as "select * from charge where charge in (1, 2, 3)". Here's the method:

public void AddFilterList(SimpleADONetField field, IEnumerable<object> criterionList, string operation = "=")
{
    List<string> quotedList = new List<string>();
    foreach (object item in criterionList)
    {
        quotedList.Add(field.GetValueString(item));
    }
    string itemString = string.Join(",", quotedList);
    AddFilter(string.Format("({0} {1} {2})", field.Name, operation, itemString));
}

I am trying to call this method like this:

chargeSet.AddFilter(chargeSet.m_charge, 1027280, ">");
List<int> numbers = new List<int>() { 1, 2, 3 };
chargeSet.AddFilterList(chargeSet.m_charge, numbers, "in");
List<string> bases = new List<string> { "01", "02", "03" };
chargeSet.AddFilterList(chargeSet.m_base, bases, "in");

I am getting an error on the first call to AddFilterList() but not on the second one. The error message reads: "Cannot convert from 'System.Collections.Generic.List' to 'System.Collections.Generic.IEnumerable'.

Why is it possible to do the conversion for a List<string> but not for a List<int>? Aren't strings and are both derived from object?

mayo
  • 3,845
  • 1
  • 32
  • 42
ROBERT RICHARDSON
  • 2,077
  • 4
  • 24
  • 57

0 Answers0