How can a dynamic be used as a generic?

前端 未结 6 475
南旧
南旧 2021-01-02 06:08

How can I use a dynamic as a generic?

This

var x = something not strongly typed;
callFunction();

and this

         


        
6条回答
  •  感动是毒
    2021-01-02 07:04

    You should be able to call the function like this

    callFunction();
    

    If your function is defined as

    public void callFunction(T arg) {
        ...
    }
    

    You can simply call it with

    callFunction(x);
    

    C# is able to infer generic type parameters in many situations.

提交回复
热议问题