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

Designing the starting markup

Let's begin with a simple markup page. Open Toolbox (Ctrl+Alt+X) and drag a Button control into the form so that you have something to click on. Change the displayed text so that the Button control says Show Product, for example. Then, place a Label control below the Button control line so that you have a place where the output should go. Your markup page should now look like the one shown in the following code block:

Figure 5.6.1: Our simple markup for this chapter

When you're learning, it's not good to have all the lines crammed together. So, separate the two lines by inserting a <br> tag at the end of the Button markup line. I've tried doing this by placing Label right after Button, but that gets really confusing when you're learning, so even a little <br> tag is helpful.

...