none
create a user interface that use an array display to words in original and reverse order in C# RRS feed

  • Question

  • I have to use an array and use a for and foreach loop.

    using

    System;


    using

    System.Collections.Generic;


    using

    System.ComponentModel;


    using

    System.Data;


    using

    System.Drawing;


    using

    System.Linq;


    using

    System.Text;


    using

    System.Threading.Tasks;


    using

    System.Windows.Forms;



    namespace

    UNIT9_Astolfo_Rios_IT254

    {

       

    publicpartialclassForm1: Form


        {

           

    publicForm1()

            {

                InitializeComponent();

            }

           

    //UNIT9_Astolfo_Rios_IT254


           

    //This project demonstrates th understanding of using C# to creat an application.


           

    //This project allows the user to enter five diffrent textboxes and display then in oreder or in reverse.


           

    //I attest this is to be my project.


           

    publicclass  words


            {

               

    publicstringWord1;

               

    publicstringWord2;

               

    publicstringWord3;

               

    publicstringWord4;

               

    publicstringWord5;

            }

           

           

    string[] wordsarray = newstring[5];

           

    protectedintcounter = 0;

     

          

           

    privatevoidbtnDisplayListsAgain_Click(objectsender, EventArgse)

            {

                word temp;

                temp.Word1 = txtWord1.Text;

                temp.Word2 = txtWord2.Text;

                temp.Word3 = txtWord3.Text;

                temp.Word4 = txtWord4.Text;

                temp.Word5 = txtWord5.Text;

                wordsarray[0] = word;

               

               

    stringword;

               

               

    for(inti = 0; i < wordsarray.length; i++)

                {

                 word =

    words[i];  

                }

               

    foreach(wordsinword)

                {

                    rchOriginalOrder.Text = word;

                }

                wordsarray.Reverse(word);

               

    foreach( wordsinword)

                {

                    rchReverseOrder.Text = word;

                }

            }

        }

    }

    • Moved by Mike DanesModerator Saturday, December 22, 2012 11:41 AM nothing to do with CLR (From:Common Language Runtime)
    Saturday, December 22, 2012 9:47 AM

Answers

  • Sorry, you should use "Length", not "length".  C# is case sensitive, and I typed the code incorrectly.

    --
    Mike
    • Proposed as answer by Jason Dot Wang Tuesday, December 25, 2012 5:55 AM
    • Marked as answer by Jason Dot Wang Monday, December 31, 2012 4:58 AM
    Sunday, December 23, 2012 9:06 PM

All replies

  • If you have an array of strings, declared as:
     
        string [] myArray = new string [] {"abc", "def", "ghi"};
     
    then the following goes through the array forwards:
     
        for (int i = 0; i < myArray.length; ++i)
            Console.WriteLine(myArray [i]);
     
    the following goes through the array in reverse:
     
        for (int i= (myArray.length - 1); i >= 0; --i)
            Console.WriteLine(myArray [i]);

    --
    Mike
    Saturday, December 22, 2012 1:49 PM
  • This solves my reverse problem. I'm still having trouble with these errors.

    Error 1 The type or namespace name 'word' could not be found (are you missing a using directive or an assembly reference?) C:\Users\Astolfo\Documents\Visual Studio 2012\Projects\UNIT9_Astolfo_Rios_IT254\UNIT9_Astolfo_Rios_IT254\Form1.cs 41 13 UNIT9_Astolfo_Rios_IT254
    Error 2 Ambiguity between 'UNIT9_Astolfo_Rios_IT254.Form1.words' and 'UNIT9_Astolfo_Rios_IT254.Form1.words' C:\Users\Astolfo\Documents\Visual Studio 2012\Projects\UNIT9_Astolfo_Rios_IT254\UNIT9_Astolfo_Rios_IT254\Form1.cs 49 33 UNIT9_Astolfo_Rios_IT254
    Error 3 'UNIT9_Astolfo_Rios_IT254.Form1.words' does not contain a definition for 'length' C:\Users\Astolfo\Documents\Visual Studio 2012\Projects\UNIT9_Astolfo_Rios_IT254\UNIT9_Astolfo_Rios_IT254\Form1.cs 49 39 UNIT9_Astolfo_Rios_IT254
    Error 4 'UNIT9_Astolfo_Rios_IT254.Form1.words' is a 'type' but is used like a 'variable' C:\Users\Astolfo\Documents\Visual Studio 2012\Projects\UNIT9_Astolfo_Rios_IT254\UNIT9_Astolfo_Rios_IT254\Form1.cs 51 34 UNIT9_Astolfo_Rios_IT254
    Error 5 Ambiguity between 'UNIT9_Astolfo_Rios_IT254.Form1.words' and 'UNIT9_Astolfo_Rios_IT254.Form1.words' C:\Users\Astolfo\Documents\Visual Studio 2012\Projects\UNIT9_Astolfo_Rios_IT254\UNIT9_Astolfo_Rios_IT254\Form1.cs 57 27 UNIT9_Astolfo_Rios_IT254
    Error 6 'UNIT9_Astolfo_Rios_IT254.Form1.words' does not contain a definition for 'length' C:\Users\Astolfo\Documents\Visual Studio 2012\Projects\UNIT9_Astolfo_Rios_IT254\UNIT9_Astolfo_Rios_IT254\Form1.cs 57 33 UNIT9_Astolfo_Rios_IT254
    Error 7 'UNIT9_Astolfo_Rios_IT254.Form1.words' is a 'type' but is used like a 'variable' C:\Users\Astolfo\Documents\Visual Studio 2012\Projects\UNIT9_Astolfo_Rios_IT254\UNIT9_Astolfo_Rios_IT254\Form1.cs 59 34 UNIT9_Astolfo_Rios_IT254
    Error 8 Type and identifier are both required in a foreach statement C:\Users\Astolfo\Documents\Visual Studio 2012\Projects\UNIT9_Astolfo_Rios_IT254\UNIT9_Astolfo_Rios_IT254\Form1.cs 51 31 UNIT9_Astolfo_Rios_IT254
    Error 9 Type and identifier are both required in a foreach statement C:\Users\Astolfo\Documents\Visual Studio 2012\Projects\UNIT9_Astolfo_Rios_IT254\UNIT9_Astolfo_Rios_IT254\Form1.cs 59 31 UNIT9_Astolfo_Rios_IT254

    Saturday, December 22, 2012 6:43 PM
  • Your original code is way too complicated...  Start with the following version.  After the code initializing the RichTextBoxes to "", you need to add code that puts the strings into the textboxes in order, either forward or reverse.  I have given you that logic already.  The code below simplifies your logic down to what is actually needed to that point.
     
    using System.Windows.Forms;
    using System;
     
    namespace Reverser
    {
     public partial class Form1 : Form
     {
      public Form1()
      {
       InitializeComponent();
      }
     
      private void btnDisplayListsAgain_Click(object sender, EventArgs e)
      {
       string[] wordsarray = new string[5];
     
       wordsarray[0] = txtWord1.Text;
       wordsarray[1] = txtWord2.Text;
       wordsarray[2] = txtWord3.Text;
       wordsarray[3] = txtWord4.Text;
       wordsarray[4] = txtWord5.Text;
     
       rchOriginalOrder.Text = "";
       rchReverseOrder.Text = "";
      }
     }
    }

    --
    Mike
    Saturday, December 22, 2012 11:51 PM
  • That helped a lot I've even input the logic you showed me but still getting some errors.

    Error 1 'System.Array' does not contain a definition for 'length' and no extension method 'length' accepting a first argument of type 'System.Array' could be found (are you missing a using directive or an assembly reference?) C:\Users\Astolfo\Documents\Visual Studio 2012\Projects\UNIT9_Astolfo_Rios_IT254\UNIT9_Astolfo_Rios_IT254\Form1.cs 37 44 UNIT9_Astolfo_Rios_IT254
    Error 2 'System.Array' does not contain a definition for 'length' and no extension method 'length' accepting a first argument of type 'System.Array' could be found (are you missing a using directive or an assembly reference?) C:\Users\Astolfo\Documents\Visual Studio 2012\Projects\UNIT9_Astolfo_Rios_IT254\UNIT9_Astolfo_Rios_IT254\Form1.cs 42 38 UNIT9_Astolfo_Rios_IT254

    Sunday, December 23, 2012 8:45 PM
  • Sorry, you should use "Length", not "length".  C# is case sensitive, and I typed the code incorrectly.

    --
    Mike
    • Proposed as answer by Jason Dot Wang Tuesday, December 25, 2012 5:55 AM
    • Marked as answer by Jason Dot Wang Monday, December 31, 2012 4:58 AM
    Sunday, December 23, 2012 9:06 PM