I want to use Tuples in my code dynamically and have to assign the values to tuple according to the if statement. I have the following code:
if(check != null)
var scoreTmpTuple = new Tuple<Guid, string, double>(
(Guid)row["sampleGuid"],
Convert.ToString(row["sampleName"]),
Convert.ToDouble(row["sampleScore"]));
else
var scoreTmpTuple = new Tuple<Guid, string, double>(
(Guid)row["exampleGuid"],
Convert.ToString(row["exampleName"]),
Convert.ToDouble(row["exampleScore"]));
In the code, the tuple is declared inside the if and else statements. I want to declare that outside and initialize the tuple accordingly.
Declare the tuple before the if statement.
Tuple<Guid, string, double> scoreTmpTuple;
if(check != null)
scoreTmpTuple = new Tuple<Guid, string, double>((Guid)row["sampleGuid"],Convert.ToString(row["sampleName"]), Convert.ToDouble(row["sampleScore"]));
else
scoreTmpTuple = new Tuple<Guid, string, double>((Guid)row["exampleGuid"],Convert.ToString(row["exampleName"]), Convert.ToDouble(row["exampleScore"]));
Just specify the type explicity instead of using var:
Tuple<Guid, string, double> scoreTmpTuple;
if (check != null)
scoreTmpTuple = Tuple.Create<Guid, string, double>(Guid.NewGuid(), "hello", 3.14);
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