Reputation: 961
Sorry, this is pretty basic but for the life of me I have not been able to solve it:
I have this:
public static IHtmlString HrefLangLinks(this PageData currentPage)
{
var availablePageLanguages = currentPage.ExistingLanguages.Select(culture => culture.Name).ToArray();
foreach (string listitem in availablePageLanguages)
{
var Output = string.Join(",", listitem);
}
// Dictionary<String, String>
return new HtmlString(Output.ToString());
}
I would like to get the results of the foreach loop outputted in the return value. But Visual Studio informs me that "Output" (the instance in my return value) does not exist in the current context.
I thought I could solve this by adding var Output ="";
outside of my foreach loop but that did not work.
Upvotes: 0
Views: 1135
Reputation: 817
Define Output before going into the foreach loop and then assign it a value:
var Output = "";
foreach (string listitem in availablePageLanguages)
{
Output = string.Join(",", listitem);
}
Apart from that I wonder if you really need a for loop in this case as you should also be able to this at once if availablePageLanguages is an array of string (string[]):
var Output = String.Join(" ", availablePageLanguages));
Upvotes: 2