Writing Code in the Code Editor

Because the code editor’s primary purpose is “word processing” for source code, let’s first look at writing the simplest of routines, a “Hello, World” function, from the ground up using the code editor.

Figure 6.4 shows a code editor with an initial stubbed-out console file. This was produced by creating a new Visual C# Console project using the Solution Explorer. Double-clicking the Program.cs file within that new project displays the source code for this console application.

Image

FIGURE 6.4 Code template for a Console code file.

As you can see, Visual Studio, as a result of the template used for creating the project, has already filled in some code.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;


namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {
        }
    }
}

To demonstrate the code editor in action, write the code that outputs the "Hello, World!" string to the Console window.

Within the Main routine, add the following.

Console.WriteLine("Hello, World!");

To begin writing the code, simply place your cursor in the window by clicking within the Main routine’s braces, press Enter to get some space for the new line of code, and type the Console.WriteLine syntax.

These and other productivity enhancers are discussed at great length in the next chapter. Here, we focus on the basics of editing and writing code in the editor window.

Now that you have seen the code editor in action (albeit for a very simple example), you’re ready to dig more into the constituent components of the editor window.


Tip

Visual Studio supports “zooming” within any open code editor/text editor. Hold down the Ctrl key and then use the mouse scroll wheel to zoom the editor view in or out.


..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset