I'M trying to learn to program through Mono. I'M using a book on C#. Although it isn't specifically for Mono, I haven't gotten far into the book and it's a really small example so I don't expect that it has any platform specific code. Please see what's wrong with this code.

namespace Song
{
	class ThisOldMan
	{
		static void Main(string[] args)
		{
			doVerse(1);
			doChorus();
			doVerse(2);
			doChorus();
		}
		
		static void doChorus()
		{
			string message = "";
			message += "\n...With a knick-knack paddy whack\n";
			message += "Give a dog a bone\n";
			message += "This old man came rolling home.";
			message += "\n\n";
		} // end doChorus
		
		static void doVerse(int verseNum)
		{
			string message = "";
			message += "This old man, he played ";
			message += verseNum;
			message += ", \nHe played knick-knack ";
			message += getPlace(verseNum);
			
			Console.WriteLine(message);
		} // end verse
		
		static string getPlace(int verseNum)
		{
			string message = "";
				switch(verseNum)
			{
			 case1:
				message = "on mu thumb ";
				break;
			 case2:
				message = "on my shoe ";
				break;
			default:
				message = "not yet defined";
				break;
			} // end switch
			return message;
		} // end getPlace
		
		static void pause()
		{
			Console.ReadLine();
		}
	}
}

The problem is in your cases inside the switch. Specifically, you're missing a space between "case" and the value your testing for.

Line 26 message += verseNum; should read message += verseNum.ToString();
You cannot assign integers to strings, so first convert your integer verseNum to a string with the ToString method.

Line 26 message += verseNum; should read message += verseNum.ToString();
You cannot assign integers to strings, so first convert your integer verseNum to a string with the ToString method.

I thought so at first, too, but that actually works. It's not best practice, that's for sure.

Thanks for pointing that out apegram! Learned something here.
Apparently you can concatenate an integer,double, boolean etc. to a string, but you are still not allowed to assign those types to a string.
Thought it was Mono, but the same under VS.

Edited 6 Years Ago by ddanbe: n/a

This article has been dead for over six months. Start a new discussion instead.