I am developing Interface for a sample project i wanted it to be as generic as possible so i created a interface like below
public interface IUserFactory
{
IEnumerable<Users> GetAll();
Users GetOne(int Id);
}
but then it happened i had to duplicate the interface to do below
public interface IProjectFactory
{
IEnumerable<Projects> GetAll(User user);
Project GetOne(int Id);
}
if you looked at above difference is just types they return, so i created something like below only to find i get error Cannot Resolve Symbol T
What am i doing wrong
public interface IFactory
{
IEnumerable<T> GetAll();
T GetOne(int Id);
}
The compiler cannot infer what the T is for. You need to declare it at the class level as well.
Try:
You need to use a generic interface/class, not just generic methods:
Defining a generic type on the interface/class ensures the type is known throughout the class (wherever the type specifier is used).
Declare the type on the interface: