Book Image

Beginning C# 7 Hands-On ??? Advanced Language Features

By : Tom Owsiak
Book Image

Beginning C# 7 Hands-On ??? Advanced Language Features

By: Tom Owsiak

Overview of this book

Beginning C# 7 Hands-On – Advanced Language Features assumes that you’ve mastered the basic elements of the C# language and that you're now ready to learn the more advanced C# language and syntax, line by line, in a working Visual Studio environment. You'll learn how to code advanced C# language topics including generics, lambda expressions, and anonymous methods. You'll learn to use query syntax to construct queries and deploy queries that perform aggregation functions. Work with C# and SQL Server 2017 to perform complex joins and stored procedures. Explore advanced file access methods, and see how to serialize and deserialize objects – all by writing working lines of code that you can run within Visual Studio. This book is designed for beginner C# developers who have mastered the basics now, and anyone who needs a fast reference to using advanced C# language features in practical coding examples. You'll also take a look at C# through web programming with web forms. By the time you’ve finished this book, you’ll know all the critical advanced elements of the C# language and how to program everything from C# generics to XML, LINQ, and your first full MVC web applications. These are the advanced building blocks that you can then combine to exploit the full power of the C# programming language, line by line.
Table of Contents (35 chapters)
Title Page
Credits
About the Author
www.PacktPub.com
Customer Feedback
Preface

Adding namespaces


First, we need to add a couple of namespaces. To do this, enter the following under using System near the top of the file:

using System.Linq;
using System.Collections.Generic;

Creating the student class and defining fields

Next, we will make a class called Student. Above the line beginning with public partial class _Default..., enter the following:

public class Student

Next, to define fields, enter the following between a set of curly braces below this line:

public string Name { get; set; }

So, little properties here, and then let's add one more. Enter the following below this line:

public List<int> Grades;

Here, List<int> is for the grades of the students, and let's name it Grades.

Making a list of students

Now, in the next stage, we will make a list of students. To do this, start by entering the following between the set of curly braces after the line that begins with protected void Button1_Click...:

List<Student> students = new List<Student>

Here, students...