Search icon CANCEL
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Conferences
Free Learning
Arrow right icon
Arrow up icon
GO TO TOP
Programming in C#: Exam 70-483 (MCSD) Guide

You're reading from   Programming in C#: Exam 70-483 (MCSD) Guide Learn basic to advanced concepts of C#, including C# 8, to pass Microsoft MCSD 70-483 exam

Arrow left icon
Product type Paperback
Published in Oct 2019
Publisher Packt
ISBN-13 9781789536577
Length 444 pages
Edition 1st Edition
Languages
Arrow right icon
Authors (2):
Arrow left icon
SrinivasMadhav Gorthi SrinivasMadhav Gorthi
Author Profile Icon SrinivasMadhav Gorthi
SrinivasMadhav Gorthi
Simaranjit Singh Bhalla Simaranjit Singh Bhalla
Author Profile Icon Simaranjit Singh Bhalla
Simaranjit Singh Bhalla
Arrow right icon
View More author details
Toc

Table of Contents (22) Chapters Close

Preface 1. Learning the Basics of C# FREE CHAPTER 2. Understanding Classes, Structures, and Interfaces 3. Understanding Object-Oriented Programming 4. Implementing Program Flow 5. Creating and Implementing Events and Callbacks 6. Managing and Implementing Multithreading 7. Implementing Exception Handling 8. Creating and Using Types in C# 9. Managing the Object Life Cycle 10. Find, Execute, and Create Types at Runtime Using Reflection 11. Validating Application Input 12. Performing Symmetric and Asymmetric Encryption 13. Managing Assemblies and Debugging Applications 14. Performing I/O Operations 15. Using LINQ Queries 16. Serialization, Deserialization, and Collections 17. Mock Test 1
18. Mock Test 2
19. Mock Test 3
20. Assessments 21. Other Books You May Enjoy

Basic structure of C#

In this section, we will go over a basic programming syntax of a C# application, namely: classes, namespaces, and assemblies.

As C# is an object-oriented language, and at the basic level it contains building blocks known as classes. The classes interact with one another, and as a result, provide functionality at runtime. A class consists of two components:

  • Data attributes: Data attributes refer to the different properties defined in the class object.
  • Methods: Methods indicate the different operations that are to be executed in the class object.

As an example, we will look at the representation of a car as an object in C#. At a very basic level, a car will have attributes such as the following:

  • Make: For example Toyota, Ford, or Honda.
  • Model: For example Mustang, Focus, or Beetle.
  • Color: Color of the car, such as Red or Black.
  • Mileage: Distance covered per liter of fuel consumed.

Please note that a car can have more attributes, but as this example is just being used for the sake of explanation, we have included these basic attributes. While writing a C# application, all of these will be captured as attributes for the Car class.

Similarly, to make sure the Car class achieves all of the desired features, it will need to implement the following operations:

  • StartEngine: This function represents how the car starts moving.
  • GainSpeed: This function represents how the car accelerates.
  • ApplyBrake: This function represents how the car applies brakes to slow down.
  • StopEngine: This function represents how the car stops.

While writing any application in C#, the starting point is always to capture all the actors/objects that are interacting with each other. Once we identify the actors, we can then identify the data attributes and methods that each of them must have so that they can exchange the required information with each other.

For the Car example being discussed, the following would be the definition of the Car class. For the sake of explanation, we have just assumed that the attributes will be of type String; however, when we go through Chapter 2, Understanding Classes, Structures, and Interfaces, we will go over some more data types that can be declared in a class. For the car example, the following syntax would be a representative program in a C# application:

class Car
{
string Make;
string Model;
string Color;
float Mileage;
void StartEngine()
{
// Implement Start Engine.
}

void GainSpeed()
{
// Implement Gain Speed.
}

void ApplyBrake()
{
// Implement Gain Speed.
}

void StopEngine()
{
// Implement Gain Speed.
}
}

In any application, there can be some classes that are related to one another. They can be based in terms of similar functionality, or they could be dependent on each other. In C#, we handle such a segregation of functionality via namespaces. For example, we can have a namespace for handling all operations related to reading/writing logs in the file directory. Similarly, we can have namespaces for handling all operations related to capturing user-specified information from inputs.

When our applications continue to evolve and we have several namespaces, we may have a need to group related namespaces under one umbrella. This ensures that if any class changes under any particular namespaces, it will not affect all the classes defined in the application. This structuring of namespace is done via assemblies in C#. Assemblies are also known as DLLs, or dynamically linked libraries. Depending upon how we structure our code, when an application is compiled, it results in multiple DLLs.

You have been reading a chapter from
Programming in C#: Exam 70-483 (MCSD) Guide
Published in: Oct 2019
Publisher: Packt
ISBN-13: 9781789536577
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at $19.99/month. Cancel anytime