0

I have an extension method like this:

 public static class Extensions
    {
        public static TOut To<TIn, TOut>(this TIn value)
        {
           .......
        }
    }

but when I want to use it, compiler can not infer the input parameter type:

var i = 0;
var res = i.To<decimal>(); //compiler error, because compiler can not infer the TIn type that is integer

the curios part is that when I am using method To without opening the < the compiler shows that TIn is integer, but when I open the <, compiler asks for TIn too. enter image description here

Arsalan
  • 709
  • 2
  • 14
  • 27
  • 4
    You have to put both as far as I know or leave both off if it is inferred. You can't do half (e.g. ). – Mike Cheel Mar 12 '20 at 18:10
  • @MikeCheel Idid same in VB.NET and it works perfectly fine – Arsalan Mar 12 '20 at 18:13
  • @Arsalan C# has different rules. All type parameters must be specified, or they must all be inferred. There's no middle ground. –  Mar 12 '20 at 18:14

0 Answers0