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 interface for this project

Remember, IS Express is the one that comes by default with the Visual Studio web server. So bring up a project. What we are going to do here is put a box under . It will start with your truck name--I'll make trucks, alright? So, put a TextBox control in here, like this. That's it:

Truck Name: <asp: TextBox ID="TextBox1" runat="server">< /asp:TextBox><br />

Now, below this, place a Button control, as follows:

<asp:Button ID="Button1" runat="server" Text="Button" /<br />

Remember to add the <br> tag at the end of the preceding lines in order to stack the content vertically.

When somebody clicks on the Button control, we'll count the number of trucks that have been made. That's all it's going to do. So, change the Text property on the...