This is going to sound really stupid, but I'm taking a class in C# where we are skipping around the book and working only from a console application. We were given an exercise to build sentences in strings based on arrays of articles, nouns, verbs, and prepositions, and capitalize the first letter in the first word of the string. The kicker is, it wants the output to a text box. That wouldn't be a problem except
a) we have bypassed all chapters regarding GUIs (that will come in the next quarter's C# class), and
b) I have checked the book and even Stack Overflow and other online sources, but couldn't figure it out.
Unfortunately, my instructor chose not to discuss this exercise in class last night. Since he and I aren't on the same page (not a dislike, more of a chemistry thing), I'm trying to figure this out on my own. And the deadline for turning this in has passed, so I'm only asking for personal edification at this point.
So, here's the code I created. I wrote it for output to a console just to show I had the basic mechanism of the problem. I know I have to create a separate form with a text box inside a GUI window, but I couldn't figure out how to send the output to a text box rather than a console.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace _16._4_StoryWriter
{
class StoryWriter
{
static void Main(string[] args)
{
string[] articles = { "the", "a", "one", "some", "any" };
string[] nouns = { "boy", "girl", "dog", "town", "car" };
string[] verbs = { "drove", "jumped", "ran", "walked", "skipped" };
string[] preps = { "to", "from", "over", "under", "on" };
string articleStory = "";
string nounStory = "";
string verbStory = "";
string prepStory = "";
Random random = new Random();
for (int counter = 1; counter <= 10; ++counter)
{
int randomNext = random.Next(5);
articleStory = articles[randomNext];
randomNext = random.Next(5);
nounStory = nouns[randomNext];
randomNext = random.Next(5);
verbStory = verbs[randomNext];
randomNext = random.Next(5);
prepStory = preps[randomNext];
Console.WriteLine(UppercaseFirst(articleStory) + " " + nounStory + " " + verbStory + " " + prepStory + ".");
} // End For
Console.Read();
} // End Main
static string UppercaseFirst(string s) // Borrowed from dotnetperls.com tutorial for making first letter uppercase
{
if (string.IsNullOrEmpty(s)) // Checks for an empty string
{
return string.Empty;
}
char[] a = s.ToCharArray(); // Creates array of characters from a string
a[0] = char.ToUpper(a[0]); // Selects value of zeroth position and changes to upper case
return new string(a); // Passes new string back
} // End method
} // End Class
} // End Namespace