SlideShare a Scribd company logo
Learn C# Programming
Structure & Enums
Eng Teong Cheah
MVP in Visual Studio & Development
Technologies
Agenda
• Structure
• Enums
C# - Structure
Structure
In C#, a structure is a value type data type. It helps you to make a single variable hold
related data of various data types. The struct keyword is used for creating a structure.
Structures are used to represent a record. Suppose you want to keep track of your
books in a library. You might want to track the following attributes about each book –
- Title
- Author
- Subject
- Book ID
Defining a Structure
To define a structure, you must use the struct statement. The struct statement defines
a new data type, with more than one member for your program.
For example, here is the way you can declare the Book structure -
Demo – Defining a Structure
Features of C# Structures
You have already used a simple structure named Books. Structures in C# are quite
different from that in traditional C or C++. The C# structures have the following
features -
- Structures can have methods, fields, indexers, properties, operator methods and
events.
- Structures can have defined constructors, but not destructors. However, you cannot
define a default constructor for a structure. The default constructor is automatically
defined and cannot be changed.
- Unlike classes, structures cannot inherit other structures or classes.
Features of C# Structures
- Structures cannot be used as a base for other structures or classes.
- A structure can implement one or more interfaces.
- Structure members cannot be specified as abstract, virtual, or protected.
- When you create a struct object using the New operator, it gets created and the
appropriate constructor is called. Unlike classes, structs can be instantiated without
using the New operator.
- If the New operator is not used, the fields remain unassigned and the object cannot
be used until all the fields are initialized.
Class versus Structure
Classes and Structures have the following basic differences –
- classes are reference types and structs are value types
- structures do not support inheritance
- structures cannot have default constructor
Demo – Class versus Structure
Enums
Enums
An enumeration is a set of named integer constants. An enumerated type is declared
using the enum keyword.
C# enumerations are value data type. In other words, enumeration contains its own
values and cannot inherit or cannot pass inheritance..
Declaring enum variable
The general syntax for declaring an enumeration is –
Where,
- The enum_name specifies the enumeration type name.
- The enumeration list is a comma-separated list of identifies.
Declaring enum variable
Each of the symbols in the enumeration list stands for an integer value, one greater
than the symbol that precedes it. By default, the value of the first enumeration symbol
is 0. For example -
Demo – Enums
Learn C# Programming
Operators & Decision Making
Eng Teong Cheah
MVP in Visual Studio & Development
Technologies
Related Content
• TutorialsPoint
www.tutorialspoint.com
Learn C# Programming
Operators & Decision Making
Eng Teong Cheah
MVP in Visual Studio & Development
Technologies
Thank you

More Related Content

PPTX
C programing -Structure
PPTX
Structure in C language
PPTX
Unit 9. Structure and Unions
PPT
Structure c
PPT
C Structures & Unions
PPT
Structure in C
PPSX
Structure
C programing -Structure
Structure in C language
Unit 9. Structure and Unions
Structure c
C Structures & Unions
Structure in C
Structure

What's hot (20)

PDF
Structures
PPTX
Structure in C
PPTX
17 structure-and-union
PPTX
Basic of Structure,Structure members,Accessing Structure member,Nested Struct...
PPTX
Presentation on c programing satcture
PPT
Unit4 C
PPT
Structure in c
PPT
User defined data type
PPT
structures and unions in 'C'
PPTX
Programming in C session 3
PPTX
Structure in c language
PPTX
CPU : Structures And Unions
PPT
pointer, structure ,union and intro to file handling
PPT
Learn c sharp at amc square learning
PPTX
Structure & union
PPT
SPC Unit 5
PPTX
C# Value Data Types and Reference Data Types
PPTX
Structure prespentation
PPTX
Structure & Union in C++
Structures
Structure in C
17 structure-and-union
Basic of Structure,Structure members,Accessing Structure member,Nested Struct...
Presentation on c programing satcture
Unit4 C
Structure in c
User defined data type
structures and unions in 'C'
Programming in C session 3
Structure in c language
CPU : Structures And Unions
pointer, structure ,union and intro to file handling
Learn c sharp at amc square learning
Structure & union
SPC Unit 5
C# Value Data Types and Reference Data Types
Structure prespentation
Structure & Union in C++
Ad

Similar to Learn C# Programming - Structure & Enums (20)

PPT
Structure and Enum in c#
PDF
fundamental programming languagech#2 (3).pdf
PDF
Unit 4 qba
PPTX
structenumtypedefunion.pptx
PPTX
8enum in c#
PPTX
C# structure
PPT
Advanced c#
PPTX
CC213-Week08-User-Defined Data Types.pptx
PDF
Structures in c++
PDF
Structures in c++
PDF
lec14.pdf
PPTX
LEARN C# PROGRAMMING WITH GMT
PDF
C- language Lecture 7
PPTX
User Defined Datatypes in C++ (Union, enum, class)
PPTX
When to use a structure vs classes in c++
PPTX
CSharp Presentation
PDF
CSharpCheatSheetV1.pdf
DOCX
Str
DOC
Structures unions
Structure and Enum in c#
fundamental programming languagech#2 (3).pdf
Unit 4 qba
structenumtypedefunion.pptx
8enum in c#
C# structure
Advanced c#
CC213-Week08-User-Defined Data Types.pptx
Structures in c++
Structures in c++
lec14.pdf
LEARN C# PROGRAMMING WITH GMT
C- language Lecture 7
User Defined Datatypes in C++ (Union, enum, class)
When to use a structure vs classes in c++
CSharp Presentation
CSharpCheatSheetV1.pdf
Str
Structures unions
Ad

More from Eng Teong Cheah (20)

PDF
Modern Cross-Platform Apps with .NET MAUI
PDF
Efficiently Removing Duplicates from a Sorted Array
PDF
Monitoring Models
PDF
Responsible Machine Learning
PDF
Training Optimal Models
PDF
Deploying Models
PDF
Machine Learning Workflows
PDF
Working with Compute
PDF
Working with Data
PDF
Experiments & TrainingModels
PDF
Automated Machine Learning
PDF
Getting Started with Azure Machine Learning
PDF
Hacking Containers - Container Storage
PDF
Hacking Containers - Looking at Cgroups
PDF
Hacking Containers - Linux Containers
PDF
Data Security - Storage Security
PDF
Application Security- App security
PDF
Application Security - Key Vault
PDF
Compute Security - Container Security
PDF
Compute Security - Host Security
Modern Cross-Platform Apps with .NET MAUI
Efficiently Removing Duplicates from a Sorted Array
Monitoring Models
Responsible Machine Learning
Training Optimal Models
Deploying Models
Machine Learning Workflows
Working with Compute
Working with Data
Experiments & TrainingModels
Automated Machine Learning
Getting Started with Azure Machine Learning
Hacking Containers - Container Storage
Hacking Containers - Looking at Cgroups
Hacking Containers - Linux Containers
Data Security - Storage Security
Application Security- App security
Application Security - Key Vault
Compute Security - Container Security
Compute Security - Host Security

Recently uploaded (20)

PPTX
Spectroscopy.pptx food analysis technology
PPTX
VMware vSphere Foundation How to Sell Presentation-Ver1.4-2-14-2024.pptx
PDF
gpt5_lecture_notes_comprehensive_20250812015547.pdf
PDF
Profit Center Accounting in SAP S/4HANA, S4F28 Col11
PPT
“AI and Expert System Decision Support & Business Intelligence Systems”
PDF
Encapsulation theory and applications.pdf
PPTX
20250228 LYD VKU AI Blended-Learning.pptx
PDF
Optimiser vos workloads AI/ML sur Amazon EC2 et AWS Graviton
PDF
Chapter 3 Spatial Domain Image Processing.pdf
DOCX
The AUB Centre for AI in Media Proposal.docx
PDF
Machine learning based COVID-19 study performance prediction
PDF
The Rise and Fall of 3GPP – Time for a Sabbatical?
PDF
Mobile App Security Testing_ A Comprehensive Guide.pdf
PDF
Review of recent advances in non-invasive hemoglobin estimation
PPTX
ACSFv1EN-58255 AWS Academy Cloud Security Foundations.pptx
PDF
Building Integrated photovoltaic BIPV_UPV.pdf
PDF
7 ChatGPT Prompts to Help You Define Your Ideal Customer Profile.pdf
PDF
Diabetes mellitus diagnosis method based random forest with bat algorithm
PDF
Approach and Philosophy of On baking technology
PDF
NewMind AI Weekly Chronicles - August'25-Week II
Spectroscopy.pptx food analysis technology
VMware vSphere Foundation How to Sell Presentation-Ver1.4-2-14-2024.pptx
gpt5_lecture_notes_comprehensive_20250812015547.pdf
Profit Center Accounting in SAP S/4HANA, S4F28 Col11
“AI and Expert System Decision Support & Business Intelligence Systems”
Encapsulation theory and applications.pdf
20250228 LYD VKU AI Blended-Learning.pptx
Optimiser vos workloads AI/ML sur Amazon EC2 et AWS Graviton
Chapter 3 Spatial Domain Image Processing.pdf
The AUB Centre for AI in Media Proposal.docx
Machine learning based COVID-19 study performance prediction
The Rise and Fall of 3GPP – Time for a Sabbatical?
Mobile App Security Testing_ A Comprehensive Guide.pdf
Review of recent advances in non-invasive hemoglobin estimation
ACSFv1EN-58255 AWS Academy Cloud Security Foundations.pptx
Building Integrated photovoltaic BIPV_UPV.pdf
7 ChatGPT Prompts to Help You Define Your Ideal Customer Profile.pdf
Diabetes mellitus diagnosis method based random forest with bat algorithm
Approach and Philosophy of On baking technology
NewMind AI Weekly Chronicles - August'25-Week II

Learn C# Programming - Structure & Enums

  • 1. Learn C# Programming Structure & Enums Eng Teong Cheah MVP in Visual Studio & Development Technologies
  • 4. Structure In C#, a structure is a value type data type. It helps you to make a single variable hold related data of various data types. The struct keyword is used for creating a structure. Structures are used to represent a record. Suppose you want to keep track of your books in a library. You might want to track the following attributes about each book – - Title - Author - Subject - Book ID
  • 5. Defining a Structure To define a structure, you must use the struct statement. The struct statement defines a new data type, with more than one member for your program. For example, here is the way you can declare the Book structure -
  • 6. Demo – Defining a Structure
  • 7. Features of C# Structures You have already used a simple structure named Books. Structures in C# are quite different from that in traditional C or C++. The C# structures have the following features - - Structures can have methods, fields, indexers, properties, operator methods and events. - Structures can have defined constructors, but not destructors. However, you cannot define a default constructor for a structure. The default constructor is automatically defined and cannot be changed. - Unlike classes, structures cannot inherit other structures or classes.
  • 8. Features of C# Structures - Structures cannot be used as a base for other structures or classes. - A structure can implement one or more interfaces. - Structure members cannot be specified as abstract, virtual, or protected. - When you create a struct object using the New operator, it gets created and the appropriate constructor is called. Unlike classes, structs can be instantiated without using the New operator. - If the New operator is not used, the fields remain unassigned and the object cannot be used until all the fields are initialized.
  • 9. Class versus Structure Classes and Structures have the following basic differences – - classes are reference types and structs are value types - structures do not support inheritance - structures cannot have default constructor
  • 10. Demo – Class versus Structure
  • 11. Enums
  • 12. Enums An enumeration is a set of named integer constants. An enumerated type is declared using the enum keyword. C# enumerations are value data type. In other words, enumeration contains its own values and cannot inherit or cannot pass inheritance..
  • 13. Declaring enum variable The general syntax for declaring an enumeration is – Where, - The enum_name specifies the enumeration type name. - The enumeration list is a comma-separated list of identifies.
  • 14. Declaring enum variable Each of the symbols in the enumeration list stands for an integer value, one greater than the symbol that precedes it. By default, the value of the first enumeration symbol is 0. For example -
  • 16. Learn C# Programming Operators & Decision Making Eng Teong Cheah MVP in Visual Studio & Development Technologies Related Content • TutorialsPoint www.tutorialspoint.com
  • 17. Learn C# Programming Operators & Decision Making Eng Teong Cheah MVP in Visual Studio & Development Technologies Thank you

Editor's Notes

  • #7: When the above code is compiled and executed, it produces the following result:
  • #11: When the above code is compiled and executed, it produces the following result:
  • #16: When the above code is compiled and executed, it produces the following result: