mercredi 8 avril 2015

int.TryParse() in if(...) directly or with variable error

I am very interested in this code, why the first version works, but the second says error:



string str = "23";

int value1;
if (int.TryParse(str, out value1)) MyInt = value1; // OK

int value2;
bool success = int.TryParse(str, out value1);
if (success) MyInt = value2; // Use of unassigned local variable 'value2'

Aucun commentaire:

Enregistrer un commentaire