You need to do it like this,
void Yourfunction(List<DateTime> dates )
{
}
working example
if list is class list then you can do like this
using System;
using System.Collections.Generic;
public class Program
{
public static void Main()
{
List<Student> list = new List<Student>();
list.Add(new Student{name= "name1", age= 21, city= "city1"});
list.Add(new Student{name= "name2", age= 22, city= "city2"});
list.Add(new Student{name= "name3", age= 24, city= "city3"});
getList(list);
}
static void getList(List<Student> list)
{
foreach(var s in list)
{
Console.WriteLine("name = "+s.name + ", age= " + s.age +", city = "+ s.city);
}
}
}
public class Student{
public string name {set; get;}
public int age {set; get;}
public string city {set; get;}
}
result
name = name1, age= 21, city = city1
name = name2, age= 22, city = city2
name = name3, age= 24, city = city3
To take a generic vs a bound List<T> you need to make the method generic as well. This is done by adding a generic parameter to the method much in the way you add it to a type. List<int>
Try the following
void Export<T>(List<T> data, params string[] parameters) {
...
}
Sadly, that's the answer. No, there is not. Not without converting it to an array (for example with )..ToArray()
You can parameterize each value in the list in an clause:IN
List<string> names = new List<string> { "john", "brian", "robert" };
string commandText = "DELETE FROM Students WHERE name IN ({0})";
string[] paramNames = names.Select(
(s, i) => "@tag" + i.ToString()
).ToArray();
string inClause = string.Join(",", paramNames);
using (var command = new SqlCommand(string.Format(commandText, inClause), con))
{
for (int i = 0; i < paramNames.Length; i++)
{
command.Parameters.AddWithValue(paramNames[i], names[i]);
}
int deleted = command.ExecuteNonQuery();
}
which is similar to:
"... WHERE Name IN (@tag0,@tag1,@tag2)"
command.Parameters["@tag0"].Value = "john";
command.Parameters["@tag1"].Value = "brian";
command.Parameters["@tag2"].Value = "robert";
Adapted from: https://stackoverflow.com/a/337792/284240