Raziaar
I Hate Custom Titles
- Joined
- Sep 13, 2003
- Messages
- 29,769
- Reaction score
- 140
This isn't for any game... i'm starting to learn C#(C sharp) for eventual migration into game development, especially with muds. I figure this is the best place to go to ask for critique on my code, for those of you who are familiar with C#.
Anyways... I didn't add really any comments, since I didn't intend to for this test program. This program is something I wrote after reading a chapter in a book called C# programming for the absolute beginner. I was trying to let the stuff in the chapter sink in, and so I tried writing this program without constant looking back and forth. Basically from memory. Can you tell me where I could improve it? I know I could/should get rid of the goto, but I wanted to include it just to say I know how to use them <grins>
What the program is supposed to do is ask the person for their name, then ask them to provide a sentence. It will then take that sentence, break it down into individual words, showing the user, then it will proceed to break each of those individual words down into the first letter of the words, then after that... the remaining letters of the word. If there are no remaining letters(a one letter word), it will notify the user of this fact.
NOTE: if this is in the wrong area(probably is), please move it to the right spot?
Anyways... I didn't add really any comments, since I didn't intend to for this test program. This program is something I wrote after reading a chapter in a book called C# programming for the absolute beginner. I was trying to let the stuff in the chapter sink in, and so I tried writing this program without constant looking back and forth. Basically from memory. Can you tell me where I could improve it? I know I could/should get rid of the goto, but I wanted to include it just to say I know how to use them <grins>
What the program is supposed to do is ask the person for their name, then ask them to provide a sentence. It will then take that sentence, break it down into individual words, showing the user, then it will proceed to break each of those individual words down into the first letter of the words, then after that... the remaining letters of the word. If there are no remaining letters(a one letter word), it will notify the user of this fact.
Code:
using System;
using System.Collections.Generic;
using System.Text;
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
string firstLetter;
string restOfWord;
string sentence;
string userName;
Console.Write("What is your name? ");
userName = Console.ReadLine();
Console.WriteLine();
Console.WriteLine("Hello there {0}. Please type a sentence and press \"enter\".", userName);
Console.WriteLine();
question:
sentence = Console.ReadLine();
if (sentence == "")
{
Console.WriteLine("You didn't type a sentence! Please type another and press \"enter\".");
Console.WriteLine();
goto question;
}
Console.WriteLine();
Console.WriteLine();
Console.WriteLine("Excellent! Now... we're going to take your sentence and divide it into words.");
Console.ReadLine();
Console.WriteLine();
foreach (string word in sentence.Split())
{
Console.WriteLine("{0}", word);
}
Console.WriteLine();
Console.WriteLine();
Console.WriteLine("Next, we're going to show you the first letter of each word.");
Console.ReadLine();
Console.WriteLine();
foreach (string word in sentence.Split())
{
firstLetter = word.Substring(0, 1);
Console.WriteLine("{0} -- is the first letter of the word: {1}", firstLetter, word);
}
Console.WriteLine();
Console.WriteLine();
Console.WriteLine("Finally, we'll show you all the rest of the letters in the word, excluding the first.");
Console.ReadLine();
Console.WriteLine();
foreach (string word in sentence.Split())
{
restOfWord = word.Substring(1, word.Length - 1);
if (restOfWord == "")
{
Console.WriteLine("\tThere are no remaining letters in the word: {0}", word);
}
else
{
Console.WriteLine();
Console.WriteLine("{0} -- are the remaining letters of the word: {1}", restOfWord, word);
}
}
Console.WriteLine();
Console.WriteLine();
Console.WriteLine("Press \"enter\" to exit the program.");
Console.ReadLine();
}//end main
}//end class
}//end namespace
NOTE: if this is in the wrong area(probably is), please move it to the right spot?