Re: My First C# (warning - long post)



andrewmcdonagh<andrewmcdonagh@xxxxxxxxx> 02/01/07 3:37 PM >>>
On Feb 1, 10:31 pm, "Frank Swarbrick" <Frank.Swarbr...@xxxxxxxxxxxxxx>
wrote:
LX-i<lxi0...@xxxxxxxxxxxx> 02/01/07 7:51 AM >>>

Along those lines - is there a better way to search through an array
other than "for (int i = 0; i < array.length; i++)"?

I'm not sure specifically what you are referring to, but, if we assume
the
above code is something like
string array[] = new string[10];
for (int i = 0; i < array.length; i++)
{
doSomething(array[i]);

}

You can replace it with

foreach (string s in array)
{
doSomething(s);

}


Good call, the other approach is to use Predicates....

see: http://www.c-sharpcorner.com/UploadFile/vandita/
PredicatesInArray10232006063515AM/PredicatesInArray.aspx

Definitely cool. I had never heard of it before. Nice use of a delegate.

Frank


---
Frank Swarbrick
Senior Developer/Analyst - Mainframe Applications
FirstBank Data Corporation - Lakewood, CO USA
.



Relevant Pages

  • Re: foreach statement output
    ... by using a 'for' statement instead of the foreach loop: ... and I will use the array to generate a string. ... know about foreach loop workings. ...
    (comp.infosystems.www.authoring.cgi)
  • Re: Trouble Using System.Array.ForEach
    ... The reason that the Array.ForEach Generic method is not suitable for your purposes in this case is that on each iteration of the 'hidden' loop, each element of the array is paseed to the Action delegate Sub, ByVal. ... Therefore the string that is passed to the delegate is returned unaltered and the parent array is not modified. ... And you may be right about the ForEach not fitting my conditions, I really can't say for sure since I have never had the opportunity to use ForEach, but either way, it never hurts to have extra knowledge so that if a situation were to come up where it was fit I would know it. ...
    (microsoft.public.dotnet.languages.vb)
  • Re: foreach pretty useless for composite classes, dont ya thunk?
    ... Change the code to look like this in your foreach within main: ... I modified your original code to include an array of ints (in addition ... public string[] FirstNames; ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: Need a simple database for name and email only
    ... function getMultipleSegments($segment, $xml) ... foreach ... $string = strtr; ... $supportedExtensions = array ( ...
    (alt.php)
  • Re: foreach statement output
    ... know about foreach loop workings. ... loop as though it was a C-style for loop. ... the number of characters in a string. ... elements in an array, we refer to the array's *size*. ...
    (comp.infosystems.www.authoring.cgi)