c# - Random Sentence Generator / Listbox output -
I am trying to create a Windows form in C #
containing 5 random words Arrays are there in them Then I will use the words from the array to create a button to generate random sentences. Right now I'm trying to output sentences in a list box but I'm getting errors Listbox What is the code to output this information? Here is my code ...
using the system; Using System.Collections.Generic; Using System.ComponentModel; Using System.Data; Using System.Drawing; Using System.Linq; Using System.Text; System usage threading. Task; Using System.Windows.Forms; Namespace Chapter_16_ Ex._16._4 {Public Partial Class Form 1: Form {Public Form 1 () {Initial Group (); } Private Zero btnGenerator_Click (Object Sender, EventArgs e) {string [] Article = {"the", "a", "one", "some", "any",}; String [] noun = {"boy", "girl", "dog", "city", "car",}; String [] verb = {"gone", "jump", "run", "gone", "left",}; String [] practice = {"from", "to", "over", "under", "on",}; Random Rndarticle = New Random (); Random Rndnoun = new Random (); Random rndverb = new random (); Random rndpreposition = new random (); Int randomarticle = rndarticle.Next (article.Length); Int randomnoun = rndnoun.ext (noun.Length); Int randomverb = rndverb.Next (verb lang); Int randompreposition = rndpreposition.ext (preposition.Length); ListBox1.Items.Add ("{0} {1}", Article [Random], noun [random]); } Private Zero btnExit_Click (Object Sender, EventArgs e) {Application.Exit (); }}}
list box.image. Add
3 parameter does not take
You must use String.Format while using '{0} {1}' and you add that value Want
listBox1.Items.Add (string.format ("{0} {1}", article [random], noun [random]]);
Or you can do this:
listBox1.Items.Add (article [random] + "" + noun [random]);
If I do this, it does the right thing.
Comments
Post a Comment