Results 1 to 3 of 3

Thread: Is this good programming practice?

  1. #1

    Thread Starter
    Member
    Join Date
    Mar 2006
    Posts
    41

    Smile Is this good programming practice?

    The following example code will compile, but I'm wondering if it's considered a good way of doing things generally?

    Code:
    for(int i = 0; i < selectedElementsFromMyArray; i++)
    {
         
    myTemporaryStorage.Add(myArray[selectedElementsFromMyArray[i]]);
    
    }
    I want to add a subset of elements from myArray into myTemporaryStorage, the indexes of the elements to be stored are held in selectedElementsFromMyArray.

    Good progarmming or bad, please let me know. Thanks.
    Last edited by The Thing; Dec 19th, 2006 at 06:44 PM.
    Using: VB.net + C#.net 2005 Express Editions + .Net Framework 2.0

    ~ Man Is The Warmest Place To Hide ~

  2. #2
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: Is this good programming practice?

    I would consider creating a second array containing only the elements of interest and then calling the AddRange method of the collection.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  3. #3

    Thread Starter
    Member
    Join Date
    Mar 2006
    Posts
    41

    Smile Re: Is this good programming practice?

    Thanks jmcilhinney, I'll try that.
    Using: VB.net + C#.net 2005 Express Editions + .Net Framework 2.0

    ~ Man Is The Warmest Place To Hide ~

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width