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
Hands-On Object-Oriented Programming with C#
Hands-On Object-Oriented Programming with C#

Hands-On Object-Oriented Programming with C#: Build maintainable software with reusable code using C#

Arrow left icon
Profile Icon Abhishek Sur Profile Icon Taher
Arrow right icon
Mex$648.99 Mex$721.99
Full star icon Full star icon Full star icon Half star icon Empty star icon 3.5 (4 Ratings)
eBook Feb 2019 288 pages 1st Edition
eBook
Mex$648.99 Mex$721.99
Paperback
Mex$902.99
Subscription
Free Trial
Arrow left icon
Profile Icon Abhishek Sur Profile Icon Taher
Arrow right icon
Mex$648.99 Mex$721.99
Full star icon Full star icon Full star icon Half star icon Empty star icon 3.5 (4 Ratings)
eBook Feb 2019 288 pages 1st Edition
eBook
Mex$648.99 Mex$721.99
Paperback
Mex$902.99
Subscription
Free Trial
eBook
Mex$648.99 Mex$721.99
Paperback
Mex$902.99
Subscription
Free Trial

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
Product feature icon AI Assistant (beta) to help accelerate your learning
OR
Modal Close icon
Payment Processing...
tick Completed

Billing Address

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

Hands-On Object-Oriented Programming with C#

Overview of C# as a Language

With the introduction of modern-day programming practices, it is evident that developers are looking for more advanced constructs to help them to deliver the best software in the most effective way. Languages that evolve on top of frameworks are built to enhance the capabilities of the developers in a way that allows them to quickly build their code with less complexity so that the code is maintainable, yet readable.

There are many high-level object, oriented programming languages available on the market, but among them I would say one of the most promising is C#. The C# language is not new in the programming world and has existed for over a decade, but with the dynamic progress of the language itself creating so many newer constructs, it has already left some of the most widely accepted language competition behind. C# is an object-oriented, type-safe, general-purpose language that is built on top of the .NET framework that was developed by Microsoft and approved by the European Computer Manufacturers Association (ECMA) and the International Standards Organization (ISO). It is built to run on the Common Language Infrastructure and can interact with any other languages that are built based on the same architecture. Inspired by C++, the language is rich in delivering the best of breed applications without handling too many complexities in code.

In this chapter, we will cover the following topics:

  • Evolution of C#
  • Architecture of C#
  • Fundamentals and syntax of the C# language
  • Visual Studio as an editor
  • Writing your first program in Visual Studio

Evolution of C#

C# has been one of the most dynamic languages in recent times. This language is open source and mostly driven by a group of software engineers, who recently came up with lots of major changes to enhance the language and provide features to handle the complexities in the languages that exist. Some of the major enhancements that have been put forward for the language include Generics, LINQ, Dynamics, and the async/await pattern:

In the preceding diagram, we can see how the language has evolved from its inception with managed code in C# 1.0, to async programming constructs that were introduced in C# 5.0, to modern-day C# 8. Before going further, let's look at some of the highlights of C# in its different stages of evolution.

Managed code

The phrase managed code came into being after Microsoft declared the .NET framework. Any code running in a managed environment is handled by Common Language Runtime (CLR), which keeps

Generics

Generics is a concept that was introduced with C# 2.0 and allows template type definition and type parameters. Generics allow the programmer to define types with open-ended type parameters that dramatically changed the way that programmers write code. The type-safety with dynamic typed generic templates improves readability, reusability, and code performance.

LINQ

The third installment of the C# language introduced Language Integrated Query (LINQ), a new construct of queries that can be run over object structures. LINQ is very new to the programming world and gives us a glimpse of functional programming on top of object-oriented general programming structure. LINQ also introduced a bunch of new interfaces in the form of the IQueryable interface, which introduced a number of libraries that can interact with the external world using LINQ. LINQ was boosted with the introduction of Lambda expressions and expression trees.

Dynamics

The fourth instalment also provides a completely new construct. It introduces the dynamic language structure. The dynamic programming capability helps the developer to defer the programming calls to runtime. There is a specific syntactic sugar that was introduced in the language that compiles the dynamic code on the same runtime. The version also puts forward a number of new interfaces and classes that enhance its language capabilities.

Async/await

With any language, threading or asynchronous programming is a pain. When dealing with asynchrony, the programmers have to come across many complexities that reduce the readability and maintainability of the code. With the async/await feature in the C# language, programming in an asynchronous way is as simple as synchronous programming. The programming has been simplified, with all of the complexities handled by the compiler and the framework internally.

Compiler as a service

Microsoft has been working on how some parts of the source code of the compiler can be opened up to the world. Consequently, as a programmer, you are capable of querying the compiler on some of its internal work principles. C# 6.0 introduced a number of libraries that enable the developer to get an insight into the compiler, the binder, the syntax tree of the program, and so on. Although the features were developed for a long time as the Roslyn project, Microsoft have finally released it to the external world.

Exception filters

C# 6.0 is adorned with a lot of smaller features. Some of the features give the developers an opportunity to implement complex logic with simple code, while some of them enhance the overall capabilities of the language. Exception filters are newly introduced with this version and give a program the capability to filter out certain exception types. The exception filters, being a CLR construct, have been hidden in the language throughout its lifetime, but were finally introduced with C# 6.0.

C# 8 and beyond

With C# being the most dynamic language in the market, it is constantly improving. With the newer features, such as nullable reference types, async streams, ranges and indices, interface members, and many other features that came with the latest version of C#, they have enhanced the basic features and helped programmers to take advantage of these new constructs, hence making their lives easier.

Note that, during the language's evolution, the .NET framework was also made open source. You can find the source code of the .NET framework at the following link: https://referencesource.microsoft.com/.

Architecture of .NET

Even though it is a decade old, the .NET framework is still well-built and makes sure to make it tiered, moduler, and hierarchical. Each tier provides specific functionalities to the user—some in terms of security and some in terms of language capabilities. The tiers produce a layer of abstraction to the end users and hide most of the complexities of the native operating system as much as possible. The .NET framework is partitioned into modules, with each of them having their own distinct responsibilities. The higher tiers request specific capabilities from the lower tiers and hence it is hierarchical.

Let's look at a diagram of the .NET architecture:

The preceding diagram depicts how the .NET framework architecture is laid out. On its lowest level, it is the operating system that interacts with the kernel APIs that are present in the operating system. The Common Language Infrastructure connects with the CLR, which provides services that monitor each code execution and managed memory, handles exceptions, and ensures that the application behaves as intended. Another important goal of the infrastructure is language inter-operability. The common language runtime is yet again abstracted with the .NET class libraries. This layer holds the binaries that the language is built on, and all of the compilers built on top of the libraries provide the same compiled code so that the CLR can understand the code and interact easily with one another.

Before going further, let's quickly look at some of the key aspects on which languages are built on the .NET framework.

Common Language Runtime

The CLR provides an interfacing between the underlying unmanaged infrastructure with the managed environment. This provides all of the basic functionalities of the managed environment in the form of garbage collection, security, and interoperability. The CLR is formed with the just-in-time compiler, which compiles the assembly code that's produced with the specific compilers to the native calls. CLR is the most important portion of the .NET architecture.

Common Type System

As there is a layer of abstraction between the language and the framework, it is evident that each of the language literals are mapped to specific CLR types. For instance, the integer of VB.NET is the same as the int of C#, as both of them point to the same type, System.Int32. It is always preferred to use language types since the compiler takes care of the mapping of types. The CTS system is built as a hierarchy of types with System.Object at its apex. The Common Type System (CTS) is divided into two kinds, one of which is value types, which are primitives that are derived from System.ValueTypes, while anything other than that is a reference type. The value types are treated differently to the reference types. This is because while allocation of memory value types are created on a thread stack during execution, reference types are always created on the heap.

.NET framework class libraries

The framework class library lies in-between the language and the CLR, and therefore any type that's present in the framework is exposed to the language you code. The .NET framework is formed with a good number of classes and structures, exposing never-ending functionalities that you, as a programmer, can benefit from. The class libraries are stored in the form of binaries that can be referenced directly from your program code.

Just-in-time compiler

.NET languages are compiled twice. During the first form of compilation, the high-level language is converted into a Microsoft Intermediate Language (MSIL), which can be understood by the CLR, while the MSIL is again compiled during runtime when the program is executed. The JIT works inside the program runtime and periodically compiles the code that is expected to be required during execution.

Left arrow icon Right arrow icon
Download code icon Download Code

Key benefits

  • Understand the four pillars of OOP; encapsulation, inheritance, abstraction and polymorphism
  • Leverage the latest features of C# 8 including nullable reference types and Async Streams
  • Explore various design patterns, principles, and best practices in OOP

Description

Object-oriented programming (OOP) is a programming paradigm organized around objects rather than actions, and data rather than logic. With the latest release of C#, you can look forward to new additions that improve object-oriented programming. This book will get you up to speed with OOP in C# in an engaging and interactive way. The book starts off by introducing you to C# language essentials and explaining OOP concepts through simple programs. You will then go on to learn how to use classes, interfacesm and properties to write pure OOP code in your applications. You will broaden your understanding of OOP further as you delve into some of the advanced features of the language, such as using events, delegates, and generics. Next, you will learn the secrets of writing good code by following design patterns and design principles. You'll also understand problem statements with their solutions and learn how to work with databases with the help of ADO.NET. Further on, you'll discover a chapter dedicated to the Git version control system. As you approach the conclusion, you'll be able to work through OOP-specific interview questions and understand how to tackle them. By the end of this book, you will have a good understanding of OOP with C# and be able to take your skills to the next level.

Who is this book for?

This book is designed for people who are new to object-oriented programming. Basic C# skills are assumed, however, prior knowledge of OOP in any other language is not required.

What you will learn

  • Master OOP paradigm fundamentals
  • Explore various types of exceptions
  • Utilize C# language constructs efficiently
  • Solve complex design problems by understanding OOP
  • Understand how to work with databases using ADO.NET
  • Understand the power of generics in C#
  • Get insights into the popular version control system, Git
  • Learn how to model and design your software

Product Details

Country selected
Publication date, Length, Edition, Language, ISBN-13
Publication date : Feb 28, 2019
Length: 288 pages
Edition : 1st
Language : English
ISBN-13 : 9781788292955
Vendor :
Microsoft
Category :
Languages :
Tools :

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
Product feature icon AI Assistant (beta) to help accelerate your learning
OR
Modal Close icon
Payment Processing...
tick Completed

Billing Address

Product Details

Publication date : Feb 28, 2019
Length: 288 pages
Edition : 1st
Language : English
ISBN-13 : 9781788292955
Vendor :
Microsoft
Category :
Languages :
Tools :

Packt Subscriptions

See our plans and pricing
Modal Close icon
$19.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
$199.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 Mex$85 each
Feature tick icon Exclusive print discounts
$279.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 Mex$85 each
Feature tick icon Exclusive print discounts

Frequently bought together


Stars icon
Total Mex$ 2,605.97
Hands-On Object-Oriented Programming with C#
Mex$902.99
Hands-On Network Programming with C# and .NET Core
Mex$902.99
Hands-On Design Patterns with C# and .NET Core
Mex$799.99
Total Mex$ 2,605.97 Stars icon

Table of Contents

15 Chapters
Overview of C# as a Language Chevron down icon Chevron up icon
Hello OOP - Classes and Objects Chevron down icon Chevron up icon
Implementation of OOP in C# Chevron down icon Chevron up icon
Object Collaboration Chevron down icon Chevron up icon
Exception Handling Chevron down icon Chevron up icon
Events and Delegates Chevron down icon Chevron up icon
Generics in C# Chevron down icon Chevron up icon
Modeling and Designing Software Chevron down icon Chevron up icon
Visual Studio and Associated Tools Chevron down icon Chevron up icon
Exploring ADO.NET with Examples Chevron down icon Chevron up icon
New Features in C# 8 Chevron down icon Chevron up icon
Understanding Design Patterns and Principles Chevron down icon Chevron up icon
Git - The Version Control System Chevron down icon Chevron up icon
Prepare Yourself - Interviews and the Future Chevron down icon Chevron up icon
Other Books You May Enjoy Chevron down icon Chevron up icon

Customer reviews

Rating distribution
Full star icon Full star icon Full star icon Half star icon Empty star icon 3.5
(4 Ratings)
5 star 50%
4 star 0%
3 star 0%
2 star 50%
1 star 0%
Sandra I Herrera-Vazquez Dec 04, 2019
Full star icon Full star icon Full star icon Full star icon Full star icon 5
Excellent book for programming
Amazon Verified review Amazon
Roland Dec 09, 2020
Full star icon Full star icon Full star icon Full star icon Full star icon 5
This book helps a lot with my software development studies. However, if you want to learn C#, this book won't be suitable for you. This book is good for learning OOP with C#.
Amazon Verified review Amazon
Blair P. Jun 14, 2021
Full star icon Full star icon Empty star icon Empty star icon Empty star icon 2
I found that the book was easy enough to read and get through. I would classify myself as a programmer making the transition between junior to mid. I am self taught, so any good book I can get is very useful. Since I have been coding a few years now in the Microsoft stack, I feel I know my way around pretty well. I was hoping to get more of a technical understanding of C# since I use it so much.The book touches on most of the important parts of programming in C#, but I don't feel it gets in depth enough to help grasp any of the concepts well enough to use them in a practical manner. The topic is introduced, the author starts to explain it, and then moves on to the next subject.Bottom line is it feels like I have more questions than answers now and I'm not sure where to turn next. I wouldn't recommend it if you're in a similar position as me. Might be good for a person very new to C# and/or programming in general.
Amazon Verified review Amazon
Amazon Customer Dec 21, 2019
Full star icon Full star icon Empty star icon Empty star icon Empty star icon 2
The author introduces material with little or no practical information to go along with it, i.e. how to actually use the topics he's discussing, and his writing style seems discombobulated. There is a lot of surface information about .NET and Visual Studio, but it doesn't go into detail about anything in a meaningful way. New syntax is introduced with no discussion on how it works and with no examples. The very first example program is dozens of lines long and makes use of programming constructs that haven't been covered. This book is not a good book to learn a new language from in my opinion. It should also be known that I am well versed in the C programming language, so I can't imagine the difficulty in being totally new to programming and trying to learn from this book.To be fair to the author, it does appear that he knows the language and the technologies very well, but I think he does not know how to write an effective textbook on the subject.
Amazon Verified review Amazon
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.