5.1. Basic class structure
Please attempt to write, compile, and execute HelloWorld.cs in the previous chapter [1] if you haven't already done so.
Let's review HelloWorld.cs. Notice that it is structurally very similar to a Java class:
1: // HelloWorld.cs 2: public class TestClass{ 3: public static void Main (){ 4: System.Console.WriteLine("Hello C#! Here I come!"); 5: } 6: }
Like Java
The Main method, and all other methods, must be inside a class [2] (or a struct – the struct will be explained in Chapter 26).
[2] In C/C++, the Main method is defined outside a class as a global method. Like Java, and unlike C/C++, C# does not support global methods or variables. Declarations of methods/variables must always ...
Get From Java to C#: A Developer's Guide 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.