Hier ein kleines Beispiel für ein C# / MONO Kommandozeilenprogramm.
Im Grunde genommen ein erweitertes HelloWorld Programm, welches etwas anzeigt, eine Benutzereingabe verlangt und das Ergebnis wieder anzeigt.
using System;
namespace HelloWorld
{
//Klasse MainClass welche eine statische Methode Main enthält, welche gleichzeitig
//der Einsprungspunkt ist
class MainClass
{
public static void Main(string[] args)
{
//Console.WriteLine schreibt etwas am Prompt
Console.WriteLine("Welcome to my first C# / MONO Application");
Console.Write("Please enter your name: ");
//name ist eine Variable des Typs string, also Text
//Console.ReadLine liest jene Eingabe ein welche zwischen der Anzeige
//am Prompt und der Eingabe von ENTER
//Der Variable name wird jene Eingabe zugewiesen
string name = Console.ReadLine();
//Ausgabe von "Your name is:" und dem Wert der Variable name
Console.WriteLine("Your Name is: " + name);
//Warten auf eine Eingabe, erst danach beendet sich das Program
Console.ReadLine();
}
}
}
bzw. von Kommentaren bereinigt:
Quellcode
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
using System;
namespace HelloWorld
{
class MainClass
{
public static void Main(string[] args)
{
Console.WriteLine("Welcome to my first C# / MONO Application");
Console.Write("Please enter your name: ");
string name = Console.ReadLine();
Console.WriteLine("Your Name is: " + name);
Console.ReadLine();
}
}
}
Si non confectus, non reficiat (If it's not broken, don't fix it) Shuttle XPC SD39P2; Intel Core2Duo 6420; Samsung T166 SATA II 3,5" 500GB; Gainward Bliss 8600GT PCX SilentFx, Cinergy T USB XS hybrid && MSI Wind Nettop && Toshiba Portege M700 && Acer Aspire One
Dieser Beitrag wurde bereits 1 mal editiert, zuletzt von »ezazazel« (10. September 2007, 21:12)