Home ยป Get started with C Sharp

Get started with C Sharp

by shedboy71

Before I start I will say that this isn’t going to be some petty post that spends lots of time justifying and then putting down other programming languages. I’ve used C# and many other languages and I personally have no real favourites. In this example we will install a text editor on our Raspberry Pi and then the development tools required to program in C#

First of all its good practice to update and upgrade first, open up the terminal and type in the following
[codesyntax lang=”bash”]

sudo apt-get update
sudo apt-get upgrade

[/codesyntax]

I quite like the geany editor there are other alernatives as well, to install this type in the following on the console
[codesyntax lang=”bash”]

sudo apt-get install geany

[/codesyntax]

Now lets install the Mono development tools required to program in C#, again at the console type the following

[codesyntax lang=”bash”]

sudo apt-get install mono-complete

[/codesyntax]

Now we will created a folder for our code called HelloWorldCs, we will navigate to that folder and then create a file in geany called HelloWorldCs.cs. In the terminal enter this

[codesyntax lang=”bash”]

mkdir HelloWorldCs
cd HelloWorldCs
geany HelloWorldCs.cs

[/codesyntax]

This will open geany now enter the following code and save it

 

[codesyntax lang=”csharp”]

using System;

public class HelloWorld
{
public static void Main()
{
Console.WriteLine("Hello Raspberry Pi!");
}
}

[/codesyntax]

 

Compile this with the following

[codesyntax lang=”bash”]

gmcs HelloWorldCs.cs

[/codesyntax]

Now run the executable

[codesyntax lang=”bash”]

mono HelloWorldCs.exe

[/codesyntax]

 

You should see something like the following, don’t worry it will get more exciting …. hopefully.

C sharp on pi

C sharp on pi

You may also like

This website uses cookies to improve your experience. We'll assume you're ok with this, but you can opt-out if you wish. Accept Read More