Search icon CANCEL
Subscription
0
Cart icon
Your Cart (0 item)
Close icon
You have no products in your basket yet
Save more on your purchases! discount-offer-chevron-icon
Savings automatically calculated. No voucher code required.
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Newsletter Hub
Free Learning
Arrow right icon
timer SALE ENDS IN
0 Days
:
00 Hours
:
00 Minutes
:
00 Seconds
Learn C# in 7 days
Learn C# in 7 days

Learn C# in 7 days: Get up and running with C# 7 with async main, tuples, pattern matching, LINQ, regex, indexers, and more

eBook
£7.99 £26.99
Paperback
£32.99
Subscription
Free Trial
Renews at £16.99p/m

What do you get with eBook?

Product feature icon Instant access to your Digital eBook purchase
Product feature icon Download this book in EPUB and PDF formats
Product feature icon Access this title in our online reader with advanced features
Product feature icon DRM FREE - Read whenever, wherever and however you want
OR
Modal Close icon
Payment Processing...
tick Completed

Billing Address

Table of content icon View table of contents Preview book icon Preview Book

Learn C# in 7 days

Day 02 - Getting Started with C#

Today, we are on day two of our seven-day learning series. Yesterday, we had gone through the basic understanding of .NET Core and its important aspects. Today, we will discuss the C# programming language. We will start with basics concepts by understanding a typical C# program, and then we will start looking at other stuff by covering reserved keywords, types, and operators; by the end of day, we will be able to write a complete C# program after covering the following topics:

  • Introducing C#
  • Understanding a typical C# program
  • An overview of C# reserved keywords, types, and operators
  • An overview of type conversion
  • Understanding statements
  • Arrays and string manipulations
  • Structure versus class

Introduction to C#

In simple words, C# (pronounced See-Sharp) is a programming language that is developed by Microsoft. C# is approved by International Standards Organization (ISO) and European Computer Manufacturers Association (ECMA).

This is the definition on the official website (https://docs.microsoft.com/en-us/dotnet/csharp/tour-of-csharp/index):

C# is a simple, modern, object-oriented, and type-safe programming language. C# has its roots in the C family of languages and will be immediately familiar to C, C++, Java, and JavaScript programmers.

Language C# is designed to adhere to Common Language Infrastructure (CLI), which we discussed on day one.

C# is the most popular professional language because of the following reasons:

  • It is an object-oriented language
  • It is component-oriented
  • It is a structured language
  • The main part that makes it the most popular: this is a part...

Understanding a typical C# program

Before we start writing a program in C#, let's first go back to day one, where we discussed the various IDEs and editors that are helpful in writing programs/applications using the C# language. Revisit day one and understand various editors and IDEs and check why we should go with one of our choice. We will be using Visual Studio 2017 update 3 for all our examples in this book.

To know the steps to install Visual Studio 2017, refer to https://docs.microsoft.com/en-us/visualstudio/install/install-visual-studio.

To get start with a simple C# program (we will create a console application), follow these steps:

  1. Initiate your Visual Studio.
  2. Go to File | New | Project (or ctrl +Shift + N).
  3. Under Visual C# node, select .NET Core and then select Console App.
  4. Name your program, say, Day02, and click on OK (see highlighted text in the following figure...

An overview of C# reserved keywords, types, and operators

Reserved keywords are nothing but predefined words that have special meaning for the compilers. You cannot use these reserved keywords as normal text or identifiers unless you explicitly tell the compiler that this word is not meant to reserve for the compiler.

In C#, you can use the reserved keyword as a normal word by prefixing the @ symbol.

C# keywords are divided into the following categories:

  • Types: In C#, the typing system is divided into value type, reference type, and pointer type.
  • Modifiers: As is self-explanatory from its name, modifiers are used to modify the declaration of types and members of a specific type.
  • Statement keywords: These are programming instructions that execute in a sequence.
  • Method parameters: These can be declared as a value type or a ref type and values can be passed using out or ref keywords...

An overview of type conversion

Type conversion means converting one type into another type. Alternatively, we call it as casting or type casting. Type conversion is broadly divided into the following categories.

Implicit conversion

Implicit conversion is the conversion that is performed by the C# compiler internally to match the the type of variable by assignment of values to that variable. This action happens implicitly, and there's no need to write any extra code to obey the type-safe mechanism. In implicit conversions, only smaller to larger types and derived classes to base class is possible.

Explicit conversion

...

Understanding statements

In C#, you can evaluate different kinds of expression that would or would not generate the results. Whenever you say something like what would happen if result >0, in that case, we are stating something. This can be a decision-making statement, result-making statement, assignment statement, or any other activity statement. On the other hand, loops are a code block that repeatedly executes a couple of statements.

In this section, we will discuss statements and loops in detail.

A statement should perform some action before returning a result. In other words, if you are writing a statement, that statement should say something. To do that, it has to execute some inbuilt or custom operations. Statements can depend upon a decision or can be a part of the result of any existing statement. The official page (https://docs.microsoft.com/en-us/dotnet/csharp...

Introduction to C#


In simple words, C# (pronounced See-Sharp) is a programming language that is developed by Microsoft. C# is approved by International Standards Organization (ISO) and European Computer Manufacturers Association (ECMA).

This is the definition on the official website (https://docs.microsoft.com/en-us/dotnet/csharp/tour-of-csharp/index):

C# is a simple, modern, object-oriented, and type-safe programming language. C# has its roots in the C family of languages and will be immediately familiar to C, C++, Java, and JavaScript programmers.

Language C# is designed to adhere to Common Language Infrastructure (CLI), which we discussed on day one.

C# is the most popular professional language because of the following reasons:

  • It is an object-oriented language
  • It is component-oriented
  • It is a structured language
  • The main part that makes it the most popular: this is a part of the .NET Framework
  • It has a unified type system, which means all types of language C# inherits from a single type object...

Understanding a typical C# program


Before we start writing a program in C#, let's first go back to day one, where we discussed the various IDEs and editors that are helpful in writing programs/applications using the C# language. Revisit day one and understand various editors and IDEs and check why we should go with one of our choice. We will be using Visual Studio 2017 update 3 for all our examples in this book.

Note

To know the steps to install Visual Studio 2017, refer to https://docs.microsoft.com/en-us/visualstudio/install/install-visual-studio.

To get start with a simple C# program (we will create a console application), follow these steps:

  1. Initiate your Visual Studio.
  2. Go to File | New | Project (or ctrl +Shift + N).
  3. Under Visual C# node, select .NET Core and then select Console App.
  4. Name your program, say, Day02, and click on OK (see highlighted text in the following figure):

You will get the following code in class Program.cs – this is the default code provided by Visual Studio; you can amend...

An overview of C# reserved keywords, types, and operators


Reserved keywords are nothing but predefined words that have special meaning for the compilers. You cannot use these reserved keywords as normal text or identifiers unless you explicitly tell the compiler that this word is not meant to reserve for the compiler.

Note

In C#, you can use the reserved keyword as a normal word by prefixing the @ symbol.

C# keywords are divided into the following categories:

  • Types: In C#, the typing system is divided into value type, reference type, and pointer type.
  • Modifiers: As is self-explanatory from its name, modifiers are used to modify the declaration of types and members of a specific type.
  • Statement keywords: These are programming instructions that execute in a sequence.
  • Method parameters: These can be declared as a value type or a ref type and values can be passed using out or ref keywords.
  • Namespace keywords: These are the keywords that belong to namespaces only.
  • Operator keywords: These operators are...

An overview of type conversion


Type conversion means converting one type into another type. Alternatively, we call it as casting or type casting. Type conversion is broadly divided into the following categories.

Implicit conversion

Implicit conversion is the conversion that is performed by the C# compiler internally to match the the type of variable by assignment of values to that variable. This action happens implicitly, and there's no need to write any extra code to obey the type-safe mechanism. In implicit conversions, only smaller to larger types and derived classes to base class is possible.

Explicit conversion

Explicit conversion is the conversion that is performed by the user explicitly with the use of the cast operator; that's why this is also known as type casting. Explicit conversion is also possible using built-in type conversion methods. For more information, refer to https://docs.microsoft.com/en-us/dotnet/csharp/language-reference/keywords/explicit-numeric-conversions-table.

Let...

Left arrow icon Right arrow icon
Download code icon Download Code

Key benefits

  • Learn the basics of C# in 7 days
  • Works as a reference guide describing the major features of C#
  • Build easy and simple code through real-world example scenarios

Description

This book takes a unique approach to teach C# to absolute beginners. You’ll learn the basics of the language in seven days. It takes a practical approach to explain the important concepts that build the foundation of the C# programming language. The book begins by teaching you the basic fundamentals using real-world practical examples and gets you acquainted with C# programming. We cover some important features and nuances of the language in a hands-on way, helping you grasp the concepts in a fluid manner. Later, you’ll explore the concepts of Object-Oriented Programming (OOP) through a real-world example. Then we dive into advanced-level concepts such as generics and collections, and you’ll get acquainted with objects and LINQ. Towards the end, you’ll build an application that covers all the concepts explained in the book. By the end of this book, you will have next-level skills and a good knowledge of the fundamentals of C#.

Who is this book for?

The book is for aspiring developers and absolute novices who want to get started with the world of programming. You do not need any knowledge of C# for this book.

What you will learn

  • Understand and set up the .NET environment
  • Code in C# using the Visual Studio 2017 RC (preferable community edition) IDE
  • Define variables, syntax, control flows, statements, and arrays etc through examples
  • Understand the concepts of Object-Oriented Programming using C#
  • Get acquainted with attributes, collection, generics, and LINQ
  • Get your hands on class members such as Modifiers, Methods, Properties, Indexers, File I/O, Exception Handling, and Regex
  • Build a real-world application using C# 7

Product Details

Country selected
Publication date, Length, Edition, Language, ISBN-13
Publication date : Oct 06, 2017
Length: 306 pages
Edition : 1st
Language : English
ISBN-13 : 9781787127159
Vendor :
Microsoft
Category :
Languages :

What do you get with eBook?

Product feature icon Instant access to your Digital eBook purchase
Product feature icon Download this book in EPUB and PDF formats
Product feature icon Access this title in our online reader with advanced features
Product feature icon DRM FREE - Read whenever, wherever and however you want
OR
Modal Close icon
Payment Processing...
tick Completed

Billing Address

Product Details

Publication date : Oct 06, 2017
Length: 306 pages
Edition : 1st
Language : English
ISBN-13 : 9781787127159
Vendor :
Microsoft
Category :
Languages :

Packt Subscriptions

See our plans and pricing
Modal Close icon
£16.99 billed monthly
Feature tick icon Unlimited access to Packt's library of 7,000+ practical books and videos
Feature tick icon Constantly refreshed with 50+ new titles a month
Feature tick icon Exclusive Early access to books as they're written
Feature tick icon Solve problems while you work with advanced search and reference features
Feature tick icon Offline reading on the mobile app
Feature tick icon Simple pricing, no contract
£169.99 billed annually
Feature tick icon Unlimited access to Packt's library of 7,000+ practical books and videos
Feature tick icon Constantly refreshed with 50+ new titles a month
Feature tick icon Exclusive Early access to books as they're written
Feature tick icon Solve problems while you work with advanced search and reference features
Feature tick icon Offline reading on the mobile app
Feature tick icon Choose a DRM-free eBook or Video every month to keep
Feature tick icon PLUS own as many other DRM-free eBooks or Videos as you like for just £5 each
Feature tick icon Exclusive print discounts
£234.99 billed in 18 months
Feature tick icon Unlimited access to Packt's library of 7,000+ practical books and videos
Feature tick icon Constantly refreshed with 50+ new titles a month
Feature tick icon Exclusive Early access to books as they're written
Feature tick icon Solve problems while you work with advanced search and reference features
Feature tick icon Offline reading on the mobile app
Feature tick icon Choose a DRM-free eBook or Video every month to keep
Feature tick icon PLUS own as many other DRM-free eBooks or Videos as you like for just £5 each
Feature tick icon Exclusive print discounts

Frequently bought together


Stars icon
Total £ 125.97
Learn C# in 7 days
£32.99
Beginning C# 7 Hands-On ??? Advanced Language Features
£32.99
C# 7.1 and .NET Core 2.0 ??? Modern Cross-Platform Development
£59.99
Total £ 125.97 Stars icon
Banner background image

Table of Contents

8 Chapters
Day 01 - Overview of the .NET Framework Chevron down icon Chevron up icon
Day 02 - Getting Started with C# Chevron down icon Chevron up icon
Day 03 - What's New in C# Chevron down icon Chevron up icon
Day 04 - Discussing C# Class Members Chevron down icon Chevron up icon
Day 05 - Overview of Reflection and Collections Chevron down icon Chevron up icon
Day 06 - Deep Dive with Advanced Concepts Chevron down icon Chevron up icon
Day 07 - Understanding Object-Oriented Programming with C# Chevron down icon Chevron up icon
Day 08 - Test Your Skills – Build a Real-World Application Chevron down icon Chevron up icon

Customer reviews

Top Reviews
Rating distribution
Full star icon Full star icon Half star icon Empty star icon Empty star icon 2.7
(7 Ratings)
5 star 28.6%
4 star 0%
3 star 28.6%
2 star 0%
1 star 42.9%
Filter icon Filter
Top Reviews

Filter reviews by




Nirmal Hota Nov 21, 2017
Full star icon Full star icon Full star icon Full star icon Full star icon 5
A nice book. Really can help to get up and grasp in days. Thanks Gaurav for this nice piece of writing.
Amazon Verified review Amazon
Ashutosh Upmanyu Nov 06, 2017
Full star icon Full star icon Full star icon Full star icon Full star icon 5
A complete justice with the title. It is a perfect book for those who have no knowledge of C# and want to learn it quickly as it is the base. Chapters are described in this book day wise with all the important screenshots as one can understand easily while doing practical. Great work by author. Recommended purchase.
Amazon Verified review Amazon
Ian Graham Apr 17, 2018
Full star icon Full star icon Full star icon Empty star icon Empty star icon 3
This book is littered with typos and grammatical errors, it does not read well. The concepts skip around a lot and most information is presented using very repetitive language. The information is decent, if you already have a strong foundation in programming concepts. This is not a book for beginners, however.If you're a seasoned programmer and you want to dive quickly into C#, and need the latest version, this is a good place to start. For a more complete experience, look elsewhere. You will be better off learning an outdated version of the language and bringing yourself up to speed on your own.
Amazon Verified review Amazon
Amazon Customer Apr 25, 2018
Full star icon Full star icon Full star icon Empty star icon Empty star icon 3
This book is not for beginners ,textual explanation is good but to follow the code snippets you have to have some prior experience with c#
Amazon Verified review Amazon
Bernhard Feb 04, 2024
Full star icon Empty star icon Empty star icon Empty star icon Empty star icon 1
Not my style of teaching. Examples not easy to understand and to much references to other sources. I want to learn a little bit of LINQ and not one example and a link?! And finally a project with no link to the source code? Can't recommend this book!
Subscriber review Packt
Get free access to Packt library with over 7500+ books and video courses for 7 days!
Start Free Trial

FAQs

How do I buy and download an eBook? Chevron down icon Chevron up icon

Where there is an eBook version of a title available, you can buy it from the book details for that title. Add either the standalone eBook or the eBook and print book bundle to your shopping cart. Your eBook will show in your cart as a product on its own. After completing checkout and payment in the normal way, you will receive your receipt on the screen containing a link to a personalised PDF download file. This link will remain active for 30 days. You can download backup copies of the file by logging in to your account at any time.

If you already have Adobe reader installed, then clicking on the link will download and open the PDF file directly. If you don't, then save the PDF file on your machine and download the Reader to view it.

Please Note: Packt eBooks are non-returnable and non-refundable.

Packt eBook and Licensing When you buy an eBook from Packt Publishing, completing your purchase means you accept the terms of our licence agreement. Please read the full text of the agreement. In it we have tried to balance the need for the ebook to be usable for you the reader with our needs to protect the rights of us as Publishers and of our authors. In summary, the agreement says:

  • You may make copies of your eBook for your own use onto any machine
  • You may not pass copies of the eBook on to anyone else
How can I make a purchase on your website? Chevron down icon Chevron up icon

If you want to purchase a video course, eBook or Bundle (Print+eBook) please follow below steps:

  1. Register on our website using your email address and the password.
  2. Search for the title by name or ISBN using the search option.
  3. Select the title you want to purchase.
  4. Choose the format you wish to purchase the title in; if you order the Print Book, you get a free eBook copy of the same title. 
  5. Proceed with the checkout process (payment to be made using Credit Card, Debit Cart, or PayPal)
Where can I access support around an eBook? Chevron down icon Chevron up icon
  • If you experience a problem with using or installing Adobe Reader, the contact Adobe directly.
  • To view the errata for the book, see www.packtpub.com/support and view the pages for the title you have.
  • To view your account details or to download a new copy of the book go to www.packtpub.com/account
  • To contact us directly if a problem is not resolved, use www.packtpub.com/contact-us
What eBook formats do Packt support? Chevron down icon Chevron up icon

Our eBooks are currently available in a variety of formats such as PDF and ePubs. In the future, this may well change with trends and development in technology, but please note that our PDFs are not Adobe eBook Reader format, which has greater restrictions on security.

You will need to use Adobe Reader v9 or later in order to read Packt's PDF eBooks.

What are the benefits of eBooks? Chevron down icon Chevron up icon
  • You can get the information you need immediately
  • You can easily take them with you on a laptop
  • You can download them an unlimited number of times
  • You can print them out
  • They are copy-paste enabled
  • They are searchable
  • There is no password protection
  • They are lower price than print
  • They save resources and space
What is an eBook? Chevron down icon Chevron up icon

Packt eBooks are a complete electronic version of the print edition, available in PDF and ePub formats. Every piece of content down to the page numbering is the same. Because we save the costs of printing and shipping the book to you, we are able to offer eBooks at a lower cost than print editions.

When you have purchased an eBook, simply login to your account and click on the link in Your Download Area. We recommend you saving the file to your hard drive before opening it.

For optimal viewing of our eBooks, we recommend you download and install the free Adobe Reader version 9.