List<int> lInt = Foo<int>();
List<string> lString = Foo<string>();
// Should either returns a List of Ints or strings
List<T> Foo<T>()
{
List<T> list = new();
for (int i = 0; i < 10; i++)
{
T valueToAdd;
if (typeof(T) == typeof(int))
{
valueToAdd = i;
}
else if (typeof(T) == typeof(string))
{
valueToAdd = i.ToString();
}
else {
throw new InvalidOperationException($"Invalid type {typeof(T)}");
}
list.Add(valueToAdd);
}
return list;
}
List<int> lInt = Foo<int>();
List<string> lString = Foo<string>();
// Should either returns a List of Ints or strings
List<T> Foo<T>()
{
List<T> list = new();
for (int i = 0; i < 10; i++)
{
T valueToAdd;
if (typeof(T) == typeof(int))
{
valueToAdd = i;
}
else if (typeof(T) == typeof(string))
{
valueToAdd = i.ToString();
}
else {
throw new InvalidOperationException($"Invalid type {typeof(T)}");
}
list.Add(valueToAdd);
}
return list;
}