Book Image

Beginning C# 7 Hands-On - The Core Language

By : Tom Owsiak
Book Image

Beginning C# 7 Hands-On - The Core Language

By: Tom Owsiak

Overview of this book

Beginning C# 7 Hands-On - The Core Language teaches you core C# language and syntax in a working Visual Studio environment. This book covers everything from core language through to more advanced features such as object-oriented programming techniques. This book is for C# 7 beginners who need a practical reference to core C# language features. You'll also gain a view of C# 7 through web programming with web forms, so you'll learn HTML, basic CSS, and how to use a variety of controls, such as buttons and drop-down lists. You'll start with the fundamentals of C# and Visual Studio, including defining variables, interacting with users, and understanding data types, data conversions, and constants. You'll move on to checking conditions using if/else blocks, and see how to use loops to do things such as repeat blocks of code. After covering various operators to evaluate and assign control structures, you'll see how to use arrays to store collections of data. By the time you’ve finished the book, you’ll know how to program the vital elements of the core C# language. These are the building blocks that you can then combine to build complex C# programs.
Table of Contents (60 chapters)
Free Chapter
1
Why C# and How to Download and Install the Visual Studio Community Edition
6
String Interpolation and Updating Visual Studio
12
Reacting to a Single Condition with If/Else Blocks
14
Repeating Blocks of Code with While Loops
15
Repeating Blocks of Code with For Loops
16
Iterating Over Collections with foreach Loops
17
Examining Multiple Variable Values with Switch Blocks
20
Operators That Evaluate and Assign in Place
21
Checking Two Conditions with the Logical AND Operator
22
Checking Two Conditions with the Logical OR Operator
28
Creating More Flexible Methods with the params Keyword
30
Combining the ref and out Keywords to Write Flexible Functions
33
Writing Easier Code with the Var and Dynamic Keywords
34
Creating a Class with a Constructor and a Function
41
Using Custom Types as Return Types
44
Using Interfaces to Express Common Behaviors
49
Overloading Operators to Perform Custom Operations
50
Using Enumerations to Represent Named Constants

Setting up the HTML for this chapter

The basic HTML for this lesson is shown in the following screenshot:

Figure 6.13.1: The basic HTML starting point for this lesson

The first thing that we are going to do is add a couple of boxes. We'll have two boxes for entering input, then we'll try to divide the values. That's the objective here. So go to Toolbox, type tex in the Search field, and then drag and drop a Textbox control into the form. Then, drag a second TextBox control directly below it. (Delete the <div> tag lines, as we won't be using them.)

Insert a Button control directly below the second TextBox control. Remember, the big idea here is to make applications that are stabler and more professional. That's the reason for having exceptions; otherwise, your stuff will be crashing all over the place and people will get frustrated and leave.

In...