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

Popular posts from this blog

c++ - Is it possible to compile a VST on linux? -

java - Output of Eclipse is rubbish -

jquery - Confused with JSON data and normal data in Django ajax request -