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.
// 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 ...Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access