O'Reilly logo

Mono: A Developer's Notebook by Niel M. Bornstein, Edd Wilder-James

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Chapter 2. Getting Started with C#

C# (pronounced see-sharp) is a powerful, modern, object-oriented language whose syntax will be familiar for developers who have used C, C++, or Java. C# takes the simplicity of Java, with its automatic garbage collection, monolithic inheritance, and standard class library, and adds a number of advanced features, such as properties, delegates, and attributes.

This chapter will get you up to speed on C# syntax, the Common Language Infrastructure types, and some features unique to C#. To run the labs in this chapter, you must have a working Mono installation as described in Chapter 1.

Say “Hello” to the World

This lab introduces some basic features of C# and the Framework Class Library (FCL). You’ll see how to write and compile a simple “Hello, world!” program in C# and learn how C# is similar to other modern, object-oriented computer languages, as well as some of the keywords and language features unique to C#. Choosing from among the panoply of Mono IDEs and installing your IDE of choice is discussed in Chapter 1.

How do I do that?

Fire up your editor or IDE of choice, and create the file Hello.cs. Enter the following code (see Example 2-1) in your editor.

Example 2-1. 01-languagebasics/Hello.cs
// 02-csharp/01-languagebasics public class HelloWorld { public static void Main (string [ ] args) { if (args.Length != 1) { System.Console.Error.WriteLine("You must tell me your name."); System.Environment.Exit(-1); } string name = args[0]; System.Console.WriteLine ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required