Writing a Simple C# Program
Let's dig in. For this first program, Listing 2.1 shows the near-minimal amount of code necessary to write a C# program. When it executes, it will print the words “Howdy, Partner!” to the console.
Listing 2.1. A Simple C# Program
1: /* 2: * FileName: HowdyParner.cs 3: * Author: Joe Mayo 4: */ 5: 6: // Program start class 7: public class HowdyPartner 8: { 9: // Main begins program execution 10: public static void Main() 11: { 12: // Write to console 13: System.Console.WriteLine("Howdy, Partner!"); 14: } 15: } |
Line 7 of Listing 2.1 shows a class declaration. Classes are what C# uses to declare or define objects. They describe the attributes and behavior of an object. An object is anything that has attributes and behavior. ...
Get C# Unleashed now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.