I'm confused as to how generics, namely T
works in C#. It doesn't seem to behave the same way as C++, unless I'm mistaken. I'm trying to create a simple interface for a data gateway:
EDIT Updated to match the answers. Visual Studio now complains the derived classes don't implement the interface methods.
public interface IDataGateway<T>
{
void InsertRow(T row);
void UpdateRow(T row);
IEnumerable<T> GetTable();
}
public class LibraryGateway : IDataGateway<Media>
{
public void InsertRow(Media item) { }
public void Updaterow(Media item) { }
public IEnumerable<Media> GetTable() { }
}
I do not know what type will be passed, which is why I'm trying to use generics.
public class LibraryGateway : IDataGateway<Media>
GetTable()
method is a little off -- you haveGetTable(T table)
in your interface, but judging from the implementation in your class, it looks like you don't actually want it to accept any parameters.