C#: Use of unassigned local variable, using a foreach and if -
i have following code:
error, "use of un-assigned local variable" i'm sure dead simple, im baffled..
public string return_result(string[,] rssdata, int marketid) { string result; foreach (var item in rssdata) { if (item.tostring() == marketid.tostring()) { result = item.tostring(); } else { result = ""; } } return result; }
initialize result when declare it. if collection empty neither of branches of if statement ever taken , result never assigned before returned.
public string return_result(string[,] rssdata, int marketid) { string result = ""; foreach (var item in rssdata) { if (item.tostring() == marketid.tostring()) { result = item.tostring(); } } return result; }
Comments
Post a Comment