How do I determine whether the types of two objects are compatible?

前端 未结 4 1238
孤城傲影
孤城傲影 2021-01-15 08:12

I have a generic function that I want to know how to write.

List something;

public int countItems(List Items)
{
    // He         


        
4条回答
  •  忘掉有多难
    2021-01-15 08:53

    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...

提交回复
热议问题