CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2

Hybrid View

  1. #1
    Join Date
    Feb 2014

    Practice Help....

    I'm bored at work, so I pull out my laptop to get some practice coding done. In class at the moment, we're working on arrays, so I thought I'd practice a bit. This isn't homework. I created a string array listing various movies I enjoy. I've also created a txtbox and a button. I'd like to know how to have an int that the user enters into the txtbox be equal (minus 1) to the index of a particular element, without having to write 10 different IF statements. Any help at all would be well appreciated.

  2. #2
    Arjay's Avatar
    Arjay is offline Moderator / MS MVP Power Poster
    Join Date
    Aug 2004

    Re: Practice Help....

    In an array, you access the array element by its index.

    So you already know that you need to subtract one from what the user gives you.

    All you need to do is pass that value (let's call it _index) to the movies array to retrieve the item.

    var movie = _movies[_index];

Posting Permissions

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

Windows Mobile Development Center

Click Here to Expand Forum to Full Width

On-Demand Webinars (sponsored)

We have made updates to our Privacy Policy to reflect the implementation of the General Data Protection Regulation.