C# 24-Hour Trainer. Stephens Rod. Читать онлайн. Newlib. NEWLIB.NET

Автор: Stephens Rod
Издательство: John Wiley & Sons Limited
Серия:
Жанр произведения: Зарубежная образовательная литература
Год издания: 0
isbn: 9781119065692
Скачать книгу
try to help you out if I can.

      Section I

      The Visual Studio IDE and Controls

      The lessons in this section of the book explain how to use the Visual Studio integrated development environment (IDE). They explain how to use the IDE to create forms, place controls on the forms, and set control properties. These lessons describe some of C#'s most useful controls and give you practice using them.

      You can do practically all of this in the IDE without writing a single line of code! That makes C# a great environment for rapid prototyping. You can build a form, add controls, and run the program to see what it looks like without ever creating a variable, declaring a method, or getting stuck in an infinite loop.

      The lessons in this section explain how to get that far. A few of these lessons show how to add a line or two of code to make a form more interesting, but for now the focus is on using the IDE to build forms and controls. Writing code (and fixing the inevitable bugs) comes later.

Lesson 1

      Getting Started with the Visual Studio IDE

      The Visual Studio integrated development environment (IDE) plays a central role in C# development. In this lesson you explore the IDE. You learn how to configure it for C# development, and you learn about some of the more useful of the IDE's windows and what they do. When you finish this lesson, you'll know how to create a new project. It may not do much, but it will run and will prepare you for the lessons that follow.

      Visual C#

      Visual Studio is a development environment that you can use with several programming languages including Visual C#, Visual Basic, Visual C++, and F#. All of those are high-level programming languages that you can use to perform complex calculations, organize your Pokémon cards, draw pretty fractals (see en.wikipedia.org/wiki/Fractal and mathworld.wolfram.com/Fractal.html), play games, download cat pictures from the Internet, and do everything else you would expect from a program.

      They can also contain bugs that delete files accidentally, discard an hour's worth of typing without warning, balance your checkbook incorrectly, and cause all sorts of other problems. Programming languages can help you do things, but they can't force you to do the right things. That's up to you.

      Visual C# combines C# with the Visual Studio development environment. You can use a text editor to write C# programs without Visual Studio, but it's a lot of work. You don't get all of the nice features that Visual Studio provides, such as special code editing features, drag-and-drop control creation, and a debugger. In short, it's a lot less fun, so I won't cover that kind of programming in this book.

      Visual C# and C# go together like hockey and fistfights: if you mention one, most people assume you're also talking about the other. Most people simply say C#, so this book does, too, unless there's a reason to distinguish between C# and Visual C#.

      The .NET Framework also plays an important role in C# programs. It includes classes that make performing certain tasks easier, runtime tools that make it possible to execute C# programs, and other plumbing necessary to build and run C# programs.

      Normally you don't need to worry about whether a feature is provided by Visual Studio, the C# language, or the .NET Framework. They all go together, so for the purposes of this book at least you can ignore the difference.

      Installing C#

      Before you can use C# to write the next blockbuster first-person Xbox game, you need to install it. So if you haven't done so already, install C#.

      You can install one of the free Express Editions at www.microsoft.com/express/Windows. As I write this, that page lists versions of Visual Studio 2015, but when you visit that page it should let you install the latest version. (I'm using a preview build of Visual Studio 2015 to write the programs that go with this book.)

      Several versions are available on that page, so be sure you pick the right one. Here's a quick summary of some of the versions that may be available:

      ● Community– This version lets you build web, Windows Store (including tablet and phone apps), Windows Desktop, Android, and iOS applications. This is probably the best version for you to download.

      ● Express for Web– This version focuses on building websites.

      ● Express for Windows– This version focuses on building Windows Phone and Windows Store apps.

      ● Express for Windows Desktop– This version focuses on desktop applications. You run these from the Windows desktop, not the start screen.

      ● Team Foundation Server Express– This edition is for people working in teams. This includes tools that you don't need right now and that can provide extra opportunities for confusion, so skip this version. (If you don't think things are confusing enough, e-mail me and I'll suggest some more confusing topics for you to study.)

      The Community Edition includes tools to get started building any of these kinds of applications, so it's a good choice. You may never use it to build websites or iOS applications, but having those abilities installed won't hurt you.

      The Express Editions are only intended to get you started, but they're seriously powerful so you probably won't need anything else for quite a while. I've been happily using Express Editions for about two decades.

      If you think you need some other version of Visual Studio (for example, you're working on a big project and you need test management, source code control, and other team programming tools), go to msdn.microsoft.com/vcsharp and install the version that's right for you.

      All of these are big installations (5 or 6 GB), so they could take a while. While a constant supply of cookies, caffeine, and conversation will help you pass the time more quickly, the other customers won't thank you if you hammer the Starbucks Wi-Fi for 12 straight hours. Be sure you have a reasonably fast connection before you start.

      Talkin' 'Bout My Generation

      Developers talk about different generations of programming languages ranging from the very primitive to the remarkably advanced. In a nutshell, the different generations of languages are:

      ● 1GL– Machine language. This is a series of 0s and 1s that the machine can understand directly. Here's a sample: 01001010 11010100 10101011 10001000. Pretty hard to read, isn't it?

      ● 2GL– Assembly language. This is a collection of mnemonic codes that represent machine language instructions. It is slightly more readable but provides no higher-level structure for performing complex tasks. Here's a sample: brfalse.s IL_0028 leave.s IL_007a ldloc.0 ldloc.1. This may be easier to read than binary, but it still looks like gibberish to me.

      ● 3GL– A higher-level language such as FORTRAN or BASIC. These provide additional structure (such as looping and subroutines) that makes building complex programs easier. Here's a sample: num_players = num_players + 1. Finally something I can read and almost understand!

      ● 4GL– An even higher-level language or a development environment that helps build programs, typically in a specific problem domain.

      ● 5GL– A language where you specify goals and constraints and the language figures out how to satisfy them. For example, the database Structured Query Language (SQL) allows you to use statements like SELECT FirstName FROM Employees. You don't need to tell the database how to get the names; it figures that out for you.

      Visual Studio provides code snippets that let you copy standard chunks of code into your program, IntelliSense that helps you select and use functions and other pieces of code, refactoring tools that help you rearrange and restructure your code, and much more. That makes Visual C# a 4GL. (Or perhaps a 3.5GL depending