Working on the rest, post suggestions as well. I am not skilled or experienced in C#
So you're willing to write your own C# programs, or simply compile someone else's code? This guide will get you started...
This FAQ assumes you're trying to compile error-free code. To actually learn the C# languages, see the How to start programming thread.
Also remember that although C# is now an ECMA standard, and mono and gmcs follow it (at this point, up to 2.0 fully), many popular libraries used by C# in Windows are not part of the standard.
0.a. Make sure the third party repositories are enabled
The easiest way to do this is open Applications->Add/Remove and select "All Available Applications".
0.b. Make sure the mono-gmcs package is installed
This package installs the essential tools needed to write and run C# programs.
Code:
sudo aptitude install mono-gmcs
1. Compiling your first C# program
Copy & paste this code into a new file. Save the file as Main.cs
PHP Code:
//First C# Program
using System;
namespace Main
{
class Welcome
{
public static void Main( string[] args )
{
Console.Write("Hello world\n");
}
}
}//Matching brace. Some people can't be pleased...
Open a terminal, go to the directory where you saved Main.cs, and type:
If all went fine, nothing is printed and you get back to the shell. Now, run it:
"Hello World!" gets printed in the terminal.
Explanations:- gmcs is the C# compiler
- obviously, Main means that the compiler must compile this file.
- mono Main.exe runs the newly compiled executable.
2. Paranoid programming is good for your health!
Many beginners want to avoid compiler errors and warnings at any cost, which often leads them to ignore the "cryptic" messages the compiler outputs and to tinker anxiously with the relevant line until the error goes away.
Don't fall in that trap! The compiler is your friend, the messages it outputs are kind advices rather than punishments. You should really take the time to try and understand those messages, this is a very good way to improve your code's quality.
As a matter of fact, most seasoned programmers set the compiler's warning level as high as possible, so that it catches the little errors they make when they aren't paying much attention.
**Help needed** Post in thread to recommend content or deletion of this section.
3. Useful tips
**Help needed** Post in thread to recommend content or deletion of this section.
4. Read the manual!
Plain old manpage:
Naturally, the Documentation and Tutorial on the Mono project site http://www.mono-project.com/ are good to visit.
You can use any editor, but MonoDevelop seems to be the IDE of choice for many C# programmers.
Thanks to so many people @UF for their very useful help, this FAQ wouldn't be the same without them. In particular, this thread is based on aks44's thread on C and C++ (see link in sticky). Not only is this thread based on it, it is blatently copying it, I hope he doesn't mind...
Bookmarks