Public Group

# Site for Code Discussion

This topic is 1216 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

Hi,

I have often wanted to ask opinion on the basic exercises I do as part of me learning C# but I don't really feel such basic questions fit on this site so I was wondering if there were any other good places for such a thing.

For example, I wrote a simple program to reverse a name, it works but I think it could be done tidier and was looking for feedback but as this site is mainly game dev (obv) I don't feel it has such a place.

If I'm wrong of course please let me know and I'll happily ask away!

##### Share on other sites

Ok great, well I made a simple console program in C# to ask your name and repeat it or reverse it.  Although it achieves what I want it to (after a few tries) I was wondering if anything is glaringly bad or could be made in a lot less code.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace NameReverser
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine("Would you like your name repeated(1) or reversed(2)");

if (choice == "1")
{
Console.WriteLine("How many times to repeat?");
int times = int.Parse(numberofTimes);

for (int i = 1; i <= times; i++)
Console.WriteLine(i + " - " + name);
}

else if (choice == "2")
{
char[] array = name.ToArray();
Array.Reverse(array);
Console.WriteLine(array);
}
else
{
Console.WriteLine("I do not understand, exiting...");
}

}
}
}


##### Share on other sites

Forgot to add my clause that I haven't got to switch statements yet (although I'm aware of what they are used for).  I was actually a bit frustrated at just how difficult I found making such a simple program.  The main issue I had was forgetting how to do the parse bit.  I'm happy if there is nothing awful there anyway!

##### Share on other sites

Ah well I suppose I would add a conditional to make sure that times >=1.  As to the other thing I'm not sure where I would even start with that, I know I have the name stored in the array and I know I can find the size of it but that's a challenge for tomorrow I think :)

Incidentally, I'm fairly sure when I was learning years ago I was told that a string was just a char array so I was surprised that I had to convert a string to an array in the first place.  I may have remembered this wrong of course (was reading C & C++)

##### Share on other sites

Ah well I suppose I would add a conditional to make sure that times >=1.  As to the other thing I'm not sure where I would even start with that, I know I have the name stored in the array and I know I can find the size of it but that's a challenge for tomorrow I think

You already have the chars put in an array. I think from there it should be obvious on how to go through it backwards

Edited by CC Ricers

##### Share on other sites

Thanks for all the replies, the patience of people on here is something else!  CC Ricers, am I thinking it's something to do with a for loop?

• 10
• 19
• 14
• 19
• 15