I've created a method:
public static Tuple<string, string, string> SplitStr(string req)
{
//...
return (A, B, C)
}
it complaint that "CSOOZQ: Cannot implicitly convert type '(strinq _keyword, strinq _filterCondition, strinq _filterCateqory)' to 'System.Tuple<strinq, strinq, string)‘"
But if code:
public static (string, string, string) SplitStr(string req)
{
//...
return (A, B, C)
}
The error goes away. From the error, it looks like the bracket form of tuple and the one Tuple<>
are different.
Tuple<>
in my case ? How do I return the Tuple ?Thanks.
The type Tuple<T1,T2,T3>
is different than the type ValueTuple<T1,T2,T3>
. In general using value-tuples is preferable to reference-type tuples, because:
My suggestion is to declare the SplitStr
like this:
public static (string First, string Middle, string Last) SplitStr(string request)
{
// ...
return (a, b, c)
}
You can then consume it like this:
var parts = SplitStr(request);
// Use parts.First, parts.Middle and parts.Last
...or using tuple deconstruction, which is also possible with reference-type tuples.
var (first, middle, last) = SplitStr(request);