I'm trying To make the method to return a Tuple of: Tuple<DateTime?, DateTime?>.
In case the code is being able to generate two DateTime types, I'm uses the Tuple.Create to create a return statement with:
public Tuple<DateTime?, DateTime?> GeTuple()
{
if (something)
{
return Tuple.Create(startDate, endDate);
}
else
{
return Tuple.Create(null, null); //--> This line produce the error.
}
}
but I'm getting this error of:
The type arguments for method 'Tuple.Create(T1, T2)' cannot be inferred from the usage. Try specifying the type arguments explicitly.
The compiler can't look at Tuple.Create(null, null) and tell that you meant to create a Tuple<DateTime?, DateTime?>. The fact that it's then being returned from a method which returns a Tuple<DateTime?, DateTime?> doesn't matter: the compiler doesn't consider that.
Use one of these:
new Tuple<DateTime?, DateTime?>(null, null)
Tuple.Create((DateTime?)null, (DateTime?)null)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With