Click here to Skip to main content
15,886,963 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
XML
Hi,
    I have the below code in my interface. I don't know the exact use of  <T> used in interface. And also please explain each terms in the code.

public interface IInterface: IDisposable
{
IEnumerable<T> GetList(Object Object);
T GetItem(Object Object);
Int32 Save(Object Object);
}


Thanks
Posted

1.First method from you interface returns a list of generic type named "T", so "T" can be replaced with any type (some of your classes, other interface, a numeric type, string, etc).

2.All methods have as parameter an object of type Object that mean that can be any object of any type.

3.Second method get a item from the given parameter and the returned value is a generic type T (see 1st point);

4.The last method it seems that save the data given and return an integer, that could be an error code.

5.The use of this interface could be to provide a general behavior for communication between layers or modules or classes that should/could be implemented by more classes, and it seems that must be implemented by classes that provide access to a list of objects of generic type "T".
 
Share this answer
 
These are two unrelated topics: generics and interfaces. Both things are related to fundamentals and need a lot of time to explain properly. Just learn each of these topics separately. Remember: you cannot be a software developer if you don't understand any of these topics, or understand not deeply enough. Everything is explained and overexplained in huge number of articles and books.

By the way, your code sample won't even compile. You need to learn how generics are declared.

After you learn it, understanding using both things together won't be a problem.

Please see:
http://msdn.microsoft.com/en-us/library/ms172192%28v=vs.110%29.aspx[^],
http://msdn.microsoft.com/en-us/library/87d83y5b.aspx[^],
http://msdn.microsoft.com/en-us/library/ms173156.aspx[^].

Please also see my past answers on interfaces:
Doubts on Interfaces[^],
POLYMORPHISM WITHOUT OVERLOADING AND OVERRRIDING IS POSSIBLE[^],
Interfaces and Polymorphism[^],
How to decide to choose Abstract class or an Interface[^],
Difference between abstract class and interface if they have same no of methods and var[^],
When we use abstract and when we use interface...?[^].

—SA
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900