Last post Nov 04, 2013 01:41 PM by Rion Williams
Nov 04, 2013 01:28 PM|nouxoid|LINK
I have a foreach containing a certain number of elements(strings, eg 25) - when i try to call the foreach results from outside the loop i cant because it is not in the same context. What would be the correct way to call these elements of the foreach loop
the loop would be like the example below:
foreach(var name = sql_query_that_calls_these_25_items into an array)
thnk you in advance for any feedback.
Nov 04, 2013 01:41 PM|Rion Williams|LINK
You would need to store the actual results in a collection and then iterate through the values of the collection :
//Example of populating your collection
var yourNames = GetYourNamesHere();
//Iterating through all of the values in your collection
foreach(var name in yourNames)
//name will refer to the current item being iterated
Alternatively, if you have a collection of items that you want to store within an array, you could like use the ToArray() method as seen below :
string names = YourSQLCallToGrabTheNames().ToArray();
Any additional information or code on how you are currently populating your values would be extremely helpful in providing a more specific answer.