I have a generic function that I want to know how to write.
List something;
public int countItems(List Items)
{
// He
The question is poorly stated and more than a little vague, but this might do it:
using System.Linq;
public int countItems<T>(List<T> Items)
{
return Items.OfType<Something>().Where(thing => thisOneCounts(thing)).Count();
}
I think what you want is to use the IComparable interface.
Another tool you may want to use is operator overloading, so that you can define how under what circumstances two objects are equal.
if (something.GetType() == items.GetType()) ...
This will compare the types of the actual objects.
do you mean:
if(typeof(T) == typeof(Something)) {...}
?
Note that having generics depend hugely on the T (and act differently) may mean what you are trying to do isn't actually very generic...