SlideShare una empresa de Scribd logo
1 de 14
Type System
Anoop K. C.
anoop@baabte.com
www.facebook.com/anoopb
aabte
twitter.com/anoop_baabte
in.linkedin.com/in/anoopbaa
bte/
+91 9746854752
C# is a strongly-typed language. Every variable and constant has a type, as does
every expression that evaluates to a value.
The information stored in a type can include the following:
The storage space that a variable of the type requires
The maximum and minimum values that it can represent.
The members (methods, fields, events, and so on) that it contains.
The base type it inherits from.
The location where the memory for variables will be allocated at run time.
The kinds of operations that are permitted.
Example
The compiler uses type information to make sure that all operations that are
performed in your code are type safe. For example, if you declare a variable of
type int, the compiler allows you to use the variable in addition and subtraction
operations. If you try to perform those same operations on a variable of type bool,
the compiler generates an error, as shown in the following example:
When we declare a variable or constant in a program, we must either specify its
type or use the var keyword to let the compiler infer the type.
After a variable is declared, it cannot be re-declared with a new type, and it
cannot be assigned a value that is not compatible with its declared type. For
example, you cannot declare an int and then assign it a Boolean value of true.
However, values can be converted to
other types, when they are assigned
to new variables or passed as method
arguments.
A type conversion that does not cause
data loss is performed automatically
by the compiler.
A conversion that might cause data
loss requires a cast in the source code.
Built-in Types
C# provides a standard set of built-in numeric types to represent integers, floating
point values, Boolean expressions, text characters, decimal values, and other types
of data.
integers
floating point values
Boolean expressions
text characters
decimal values &
other types of data.
There are also built-in string and object types.
These are available to use in any C# program
Custom Types
We use the struct, class, interface, and enum constructs to create our own custom
types.
By default, the most frequently used types in the class library are available in any
C# program. Others become available only when we explicitly add a project
reference to the assembly in which they are defined.
After the compiler has a reference to the assembly, we can declare variables (and
constants) of the types declared in that assembly in source code.
The common type system
It is important to understand two fundamental points about the type system in
the .NET Framework:
It supports the principle of inheritance, that means, types can derive from
other types, called base types. All types derive ultimately from a single base
type, which is System.Object (C# keyword: object). This unified type hierarchy
is called the Common Type System (CTS).
Each type in the CTS is defined as either a value type or a reference type.
•Types that you define by using the struct keyword are value types
•Types that you define by using the class keyword are reference types
Reference types and value types have different compile-time rules, and different
run-time behavior.
Value types
Value type variables directly contain their values
the memory is allocated inline in whatever context the variable is declared
There is no separate heap allocation or garbage collection overhead for value-
type variables.
There are two categories of value types: struct and enum.
Value types are sealed, that means they does not allow inheritance
Reference types
A type that is defined as a class, delegate, array, or interface is a reference type.
At run time, when we declare a variable of a reference type, the variable
contains the value null until we explicitly create an instance of the object by using
the new operator, or assign it an object that has been created elsewhere by
using new
When a reference type variable is created, the memory is allocated on the
managed heap, and the variable holds only a reference to the location of the
object.
All arrays are reference types, even if their elements are value types.
Reference types fully support inheritance.
Generic types
A type which is declared with one or more type parameters that serve as a
placeholder for the actual type (the concrete type) that client code will provide
when it creates an instance of the type.
For example, the .NET Framework type System.Collections.Generic.List<T> has one
type parameter that by convention is given the name T. When you create an
instance of the type, you specify the type of the objects that the list will contain,
for example, string:
List<string> strings = new List<string>();
The use of the type parameter makes it possible to reuse the same class to hold
any type of element
Generic collection types are strongly typed
Implicit Types, Anonymous Types, and Nullable Types
We can implicitly type a local variable (but not class members) by using
the var keyword. The variable still receives a type at compile time, but the type is
provided by the compiler.
Anonymous types are types those have scope only inside the method in which
they are defined. The compiler itself will create an arbitrary class for such types,
giving us the advantage of not having to define a class for a type that is only used
inside a single method. Anonymous types are immutable.
Anonymous types provide a convenient way to encapsulate a set of read-only
properties into a single object without having to explicitly define a type first. The
type name is generated by the compiler and is not available at the source code
level. The type of each property is inferred by the compiler.
Ordinary value types cannot have a value of null. we can create nullable value
types by affixing a ? after the type. For example, int? is an int type that can also
have the value null.
Follow us @ twitter.com/baabtra
Like us @ facebook.com/baabtra
Subscribe to us @ youtube.com/baabtra
Become a follower @ slideshare.net/BaabtraMentoringPartner
Connect to us @ in.linkedin.com/in/baabtra
Thanks in advance.
www.baabtra.com | www.massbaab.com |www.baabte.com
Contact Us
Emarald Mall (Big Bazar Building)
Mavoor Road, Kozhikode,
Kerala, India.
Ph: + 91 – 495 40 25 550
NC Complex, Near Bus Stand
Mukkam, Kozhikode,
Kerala, India.
Ph: + 91 – 495 40 25 550
Cafit Square,
Hilite Business Park,
Near Pantheerankavu,
Kozhikode
Start up Village
Eranakulam,
Kerala, India.
Email: info@baabtra.com

Más contenido relacionado

La actualidad más candente

context free language
context free languagecontext free language
context free languagekhush_boo31
 
Instruction Set Architecture (ISA)
Instruction Set Architecture (ISA)Instruction Set Architecture (ISA)
Instruction Set Architecture (ISA)Gaditek
 
USER INTERFACE DESIGN PPT
USER INTERFACE DESIGN PPTUSER INTERFACE DESIGN PPT
USER INTERFACE DESIGN PPTvicci4041
 
Lecture 04 syntax analysis
Lecture 04 syntax analysisLecture 04 syntax analysis
Lecture 04 syntax analysisIffat Anjum
 
Syntax Analysis in Compiler Design
Syntax Analysis in Compiler Design Syntax Analysis in Compiler Design
Syntax Analysis in Compiler Design MAHASREEM
 
Services provided by os
Services provided by osServices provided by os
Services provided by osSumant Diwakar
 
Basic blocks and control flow graphs
Basic blocks and control flow graphsBasic blocks and control flow graphs
Basic blocks and control flow graphsTilakpoudel2
 
Predicate Logic
Predicate LogicPredicate Logic
Predicate Logicgiki67
 
Knowledge based agent
Knowledge based agentKnowledge based agent
Knowledge based agentShiwani Gupta
 
Chapter 1 - INTRODUCTION TO PYTHON -MAULIK BORSANIYA
Chapter 1 - INTRODUCTION TO PYTHON -MAULIK BORSANIYAChapter 1 - INTRODUCTION TO PYTHON -MAULIK BORSANIYA
Chapter 1 - INTRODUCTION TO PYTHON -MAULIK BORSANIYAMaulik Borsaniya
 
RECURSION IN C
RECURSION IN C RECURSION IN C
RECURSION IN C v_jk
 

La actualidad más candente (20)

context free language
context free languagecontext free language
context free language
 
Python programming : Standard Input and Output
Python programming : Standard Input and OutputPython programming : Standard Input and Output
Python programming : Standard Input and Output
 
Instruction Set Architecture (ISA)
Instruction Set Architecture (ISA)Instruction Set Architecture (ISA)
Instruction Set Architecture (ISA)
 
Compiler design
Compiler designCompiler design
Compiler design
 
USER INTERFACE DESIGN PPT
USER INTERFACE DESIGN PPTUSER INTERFACE DESIGN PPT
USER INTERFACE DESIGN PPT
 
Lecture 04 syntax analysis
Lecture 04 syntax analysisLecture 04 syntax analysis
Lecture 04 syntax analysis
 
Back patching
Back patchingBack patching
Back patching
 
Syntax Analysis in Compiler Design
Syntax Analysis in Compiler Design Syntax Analysis in Compiler Design
Syntax Analysis in Compiler Design
 
Peephole Optimization
Peephole OptimizationPeephole Optimization
Peephole Optimization
 
Services provided by os
Services provided by osServices provided by os
Services provided by os
 
Basic blocks and control flow graphs
Basic blocks and control flow graphsBasic blocks and control flow graphs
Basic blocks and control flow graphs
 
Data types
Data typesData types
Data types
 
Data types in C
Data types in CData types in C
Data types in C
 
Predicate Logic
Predicate LogicPredicate Logic
Predicate Logic
 
Knowledge based agent
Knowledge based agentKnowledge based agent
Knowledge based agent
 
Break and continue
Break and continueBreak and continue
Break and continue
 
Chapter 1 - INTRODUCTION TO PYTHON -MAULIK BORSANIYA
Chapter 1 - INTRODUCTION TO PYTHON -MAULIK BORSANIYAChapter 1 - INTRODUCTION TO PYTHON -MAULIK BORSANIYA
Chapter 1 - INTRODUCTION TO PYTHON -MAULIK BORSANIYA
 
Operators in python
Operators in pythonOperators in python
Operators in python
 
RECURSION IN C
RECURSION IN C RECURSION IN C
RECURSION IN C
 
Chapter 5 Syntax Directed Translation
Chapter 5   Syntax Directed TranslationChapter 5   Syntax Directed Translation
Chapter 5 Syntax Directed Translation
 

Destacado

презентація пирлик
презентація пирликпрезентація пирлик
презентація пирликpoljakova
 
RUCUG: 11. Rick Dehlinger BYOC: Beware the Perimeter
RUCUG: 11. Rick Dehlinger BYOC: Beware the PerimeterRUCUG: 11. Rick Dehlinger BYOC: Beware the Perimeter
RUCUG: 11. Rick Dehlinger BYOC: Beware the PerimeterDenis Gundarev
 
Mba tiltle for 2012
Mba tiltle for 2012Mba tiltle for 2012
Mba tiltle for 2012Soundar Msr
 
Webservices.nl & data quality
Webservices.nl & data qualityWebservices.nl & data quality
Webservices.nl & data qualityHarold1978
 

Destacado (7)

Presentación1
Presentación1Presentación1
Presentación1
 
презентація пирлик
презентація пирликпрезентація пирлик
презентація пирлик
 
Test Prep Presentation for NJROTC students in 2004, part 1
Test Prep Presentation for NJROTC students in 2004, part 1Test Prep Presentation for NJROTC students in 2004, part 1
Test Prep Presentation for NJROTC students in 2004, part 1
 
RUCUG: 11. Rick Dehlinger BYOC: Beware the Perimeter
RUCUG: 11. Rick Dehlinger BYOC: Beware the PerimeterRUCUG: 11. Rick Dehlinger BYOC: Beware the Perimeter
RUCUG: 11. Rick Dehlinger BYOC: Beware the Perimeter
 
Mba tiltle for 2012
Mba tiltle for 2012Mba tiltle for 2012
Mba tiltle for 2012
 
IDC 2012 MEA & Turkey Predictions
IDC 2012 MEA & Turkey PredictionsIDC 2012 MEA & Turkey Predictions
IDC 2012 MEA & Turkey Predictions
 
Webservices.nl & data quality
Webservices.nl & data qualityWebservices.nl & data quality
Webservices.nl & data quality
 

Similar a C# Type System Overview

Similar a C# Type System Overview (20)

LEARN C# PROGRAMMING WITH GMT
LEARN C# PROGRAMMING WITH GMTLEARN C# PROGRAMMING WITH GMT
LEARN C# PROGRAMMING WITH GMT
 
Typescript: Beginner to Advanced
Typescript: Beginner to AdvancedTypescript: Beginner to Advanced
Typescript: Beginner to Advanced
 
Dot net programming concept
Dot net  programming conceptDot net  programming concept
Dot net programming concept
 
A tour of C# - Overview _ Microsoft Learn.pdf
A tour of C# - Overview _ Microsoft Learn.pdfA tour of C# - Overview _ Microsoft Learn.pdf
A tour of C# - Overview _ Microsoft Learn.pdf
 
Unit 1 question and answer
Unit 1 question and answerUnit 1 question and answer
Unit 1 question and answer
 
CSharpCheatSheetV1.pdf
CSharpCheatSheetV1.pdfCSharpCheatSheetV1.pdf
CSharpCheatSheetV1.pdf
 
Data Types, Variables, and Constants in C# Programming
Data Types, Variables, and Constants in C# ProgrammingData Types, Variables, and Constants in C# Programming
Data Types, Variables, and Constants in C# Programming
 
typescript.pptx
typescript.pptxtypescript.pptx
typescript.pptx
 
Introduction of C# BY Adarsh Singh
Introduction of C# BY Adarsh SinghIntroduction of C# BY Adarsh Singh
Introduction of C# BY Adarsh Singh
 
3rd june
3rd june3rd june
3rd june
 
C# chap 4
C# chap 4C# chap 4
C# chap 4
 
C# concepts
C# conceptsC# concepts
C# concepts
 
ActionScript 3.0 Fundamentals
ActionScript 3.0 FundamentalsActionScript 3.0 Fundamentals
ActionScript 3.0 Fundamentals
 
Visual Basic User Interface -IV
Visual Basic User Interface -IVVisual Basic User Interface -IV
Visual Basic User Interface -IV
 
Objects and Types C#
Objects and Types C#Objects and Types C#
Objects and Types C#
 
Type Checking
Type CheckingType Checking
Type Checking
 
2.Getting Started with C#.Net-(C#)
2.Getting Started with C#.Net-(C#)2.Getting Started with C#.Net-(C#)
2.Getting Started with C#.Net-(C#)
 
Notes(1).pptx
Notes(1).pptxNotes(1).pptx
Notes(1).pptx
 
Chapter 2 c#
Chapter 2 c#Chapter 2 c#
Chapter 2 c#
 
TypeScript Overview
TypeScript OverviewTypeScript Overview
TypeScript Overview
 

Más de baabtra.com - No. 1 supplier of quality freshers

Más de baabtra.com - No. 1 supplier of quality freshers (20)

Agile methodology and scrum development
Agile methodology and scrum developmentAgile methodology and scrum development
Agile methodology and scrum development
 
Best coding practices
Best coding practicesBest coding practices
Best coding practices
 
Core java - baabtra
Core java - baabtraCore java - baabtra
Core java - baabtra
 
Acquiring new skills what you should know
Acquiring new skills   what you should knowAcquiring new skills   what you should know
Acquiring new skills what you should know
 
Baabtra.com programming at school
Baabtra.com programming at schoolBaabtra.com programming at school
Baabtra.com programming at school
 
99LMS for Enterprises - LMS that you will love
99LMS for Enterprises - LMS that you will love 99LMS for Enterprises - LMS that you will love
99LMS for Enterprises - LMS that you will love
 
Php sessions & cookies
Php sessions & cookiesPhp sessions & cookies
Php sessions & cookies
 
Php database connectivity
Php database connectivityPhp database connectivity
Php database connectivity
 
Chapter 6 database normalisation
Chapter 6  database normalisationChapter 6  database normalisation
Chapter 6 database normalisation
 
Chapter 5 transactions and dcl statements
Chapter 5  transactions and dcl statementsChapter 5  transactions and dcl statements
Chapter 5 transactions and dcl statements
 
Chapter 4 functions, views, indexing
Chapter 4  functions, views, indexingChapter 4  functions, views, indexing
Chapter 4 functions, views, indexing
 
Chapter 3 stored procedures
Chapter 3 stored proceduresChapter 3 stored procedures
Chapter 3 stored procedures
 
Chapter 2 grouping,scalar and aggergate functions,joins inner join,outer join
Chapter 2  grouping,scalar and aggergate functions,joins   inner join,outer joinChapter 2  grouping,scalar and aggergate functions,joins   inner join,outer join
Chapter 2 grouping,scalar and aggergate functions,joins inner join,outer join
 
Chapter 1 introduction to sql server
Chapter 1 introduction to sql serverChapter 1 introduction to sql server
Chapter 1 introduction to sql server
 
Chapter 1 introduction to sql server
Chapter 1 introduction to sql serverChapter 1 introduction to sql server
Chapter 1 introduction to sql server
 
Microsoft holo lens
Microsoft holo lensMicrosoft holo lens
Microsoft holo lens
 
Blue brain
Blue brainBlue brain
Blue brain
 
5g
5g5g
5g
 
Aptitude skills baabtra
Aptitude skills baabtraAptitude skills baabtra
Aptitude skills baabtra
 
Gd baabtra
Gd baabtraGd baabtra
Gd baabtra
 

Último

Ahmed Motair CV April 2024 (Senior SW Developer)
Ahmed Motair CV April 2024 (Senior SW Developer)Ahmed Motair CV April 2024 (Senior SW Developer)
Ahmed Motair CV April 2024 (Senior SW Developer)Ahmed Mater
 
CRM Contender Series: HubSpot vs. Salesforce
CRM Contender Series: HubSpot vs. SalesforceCRM Contender Series: HubSpot vs. Salesforce
CRM Contender Series: HubSpot vs. SalesforceBrainSell Technologies
 
Call Us🔝>༒+91-9711147426⇛Call In girls karol bagh (Delhi)
Call Us🔝>༒+91-9711147426⇛Call In girls karol bagh (Delhi)Call Us🔝>༒+91-9711147426⇛Call In girls karol bagh (Delhi)
Call Us🔝>༒+91-9711147426⇛Call In girls karol bagh (Delhi)jennyeacort
 
Machine Learning Software Engineering Patterns and Their Engineering
Machine Learning Software Engineering Patterns and Their EngineeringMachine Learning Software Engineering Patterns and Their Engineering
Machine Learning Software Engineering Patterns and Their EngineeringHironori Washizaki
 
SensoDat: Simulation-based Sensor Dataset of Self-driving Cars
SensoDat: Simulation-based Sensor Dataset of Self-driving CarsSensoDat: Simulation-based Sensor Dataset of Self-driving Cars
SensoDat: Simulation-based Sensor Dataset of Self-driving CarsChristian Birchler
 
Tech Tuesday - Mastering Time Management Unlock the Power of OnePlan's Timesh...
Tech Tuesday - Mastering Time Management Unlock the Power of OnePlan's Timesh...Tech Tuesday - Mastering Time Management Unlock the Power of OnePlan's Timesh...
Tech Tuesday - Mastering Time Management Unlock the Power of OnePlan's Timesh...OnePlan Solutions
 
How To Manage Restaurant Staff -BTRESTRO
How To Manage Restaurant Staff -BTRESTROHow To Manage Restaurant Staff -BTRESTRO
How To Manage Restaurant Staff -BTRESTROmotivationalword821
 
Open Source Summit NA 2024: Open Source Cloud Costs - OpenCost's Impact on En...
Open Source Summit NA 2024: Open Source Cloud Costs - OpenCost's Impact on En...Open Source Summit NA 2024: Open Source Cloud Costs - OpenCost's Impact on En...
Open Source Summit NA 2024: Open Source Cloud Costs - OpenCost's Impact on En...Matt Ray
 
20240415 [Container Plumbing Days] Usernetes Gen2 - Kubernetes in Rootless Do...
20240415 [Container Plumbing Days] Usernetes Gen2 - Kubernetes in Rootless Do...20240415 [Container Plumbing Days] Usernetes Gen2 - Kubernetes in Rootless Do...
20240415 [Container Plumbing Days] Usernetes Gen2 - Kubernetes in Rootless Do...Akihiro Suda
 
Introduction Computer Science - Software Design.pdf
Introduction Computer Science - Software Design.pdfIntroduction Computer Science - Software Design.pdf
Introduction Computer Science - Software Design.pdfFerryKemperman
 
Software Project Health Check: Best Practices and Techniques for Your Product...
Software Project Health Check: Best Practices and Techniques for Your Product...Software Project Health Check: Best Practices and Techniques for Your Product...
Software Project Health Check: Best Practices and Techniques for Your Product...Velvetech LLC
 
Salesforce Implementation Services PPT By ABSYZ
Salesforce Implementation Services PPT By ABSYZSalesforce Implementation Services PPT By ABSYZ
Salesforce Implementation Services PPT By ABSYZABSYZ Inc
 
Recruitment Management Software Benefits (Infographic)
Recruitment Management Software Benefits (Infographic)Recruitment Management Software Benefits (Infographic)
Recruitment Management Software Benefits (Infographic)Hr365.us smith
 
Taming Distributed Systems: Key Insights from Wix's Large-Scale Experience - ...
Taming Distributed Systems: Key Insights from Wix's Large-Scale Experience - ...Taming Distributed Systems: Key Insights from Wix's Large-Scale Experience - ...
Taming Distributed Systems: Key Insights from Wix's Large-Scale Experience - ...Natan Silnitsky
 
How to submit a standout Adobe Champion Application
How to submit a standout Adobe Champion ApplicationHow to submit a standout Adobe Champion Application
How to submit a standout Adobe Champion ApplicationBradBedford3
 
MYjobs Presentation Django-based project
MYjobs Presentation Django-based projectMYjobs Presentation Django-based project
MYjobs Presentation Django-based projectAnoyGreter
 
Implementing Zero Trust strategy with Azure
Implementing Zero Trust strategy with AzureImplementing Zero Trust strategy with Azure
Implementing Zero Trust strategy with AzureDinusha Kumarasiri
 
UI5ers live - Custom Controls wrapping 3rd-party libs.pptx
UI5ers live - Custom Controls wrapping 3rd-party libs.pptxUI5ers live - Custom Controls wrapping 3rd-party libs.pptx
UI5ers live - Custom Controls wrapping 3rd-party libs.pptxAndreas Kunz
 
Balasore Best It Company|| Top 10 IT Company || Balasore Software company Odisha
Balasore Best It Company|| Top 10 IT Company || Balasore Software company OdishaBalasore Best It Company|| Top 10 IT Company || Balasore Software company Odisha
Balasore Best It Company|| Top 10 IT Company || Balasore Software company Odishasmiwainfosol
 

Último (20)

Ahmed Motair CV April 2024 (Senior SW Developer)
Ahmed Motair CV April 2024 (Senior SW Developer)Ahmed Motair CV April 2024 (Senior SW Developer)
Ahmed Motair CV April 2024 (Senior SW Developer)
 
CRM Contender Series: HubSpot vs. Salesforce
CRM Contender Series: HubSpot vs. SalesforceCRM Contender Series: HubSpot vs. Salesforce
CRM Contender Series: HubSpot vs. Salesforce
 
Call Us🔝>༒+91-9711147426⇛Call In girls karol bagh (Delhi)
Call Us🔝>༒+91-9711147426⇛Call In girls karol bagh (Delhi)Call Us🔝>༒+91-9711147426⇛Call In girls karol bagh (Delhi)
Call Us🔝>༒+91-9711147426⇛Call In girls karol bagh (Delhi)
 
Machine Learning Software Engineering Patterns and Their Engineering
Machine Learning Software Engineering Patterns and Their EngineeringMachine Learning Software Engineering Patterns and Their Engineering
Machine Learning Software Engineering Patterns and Their Engineering
 
SensoDat: Simulation-based Sensor Dataset of Self-driving Cars
SensoDat: Simulation-based Sensor Dataset of Self-driving CarsSensoDat: Simulation-based Sensor Dataset of Self-driving Cars
SensoDat: Simulation-based Sensor Dataset of Self-driving Cars
 
Tech Tuesday - Mastering Time Management Unlock the Power of OnePlan's Timesh...
Tech Tuesday - Mastering Time Management Unlock the Power of OnePlan's Timesh...Tech Tuesday - Mastering Time Management Unlock the Power of OnePlan's Timesh...
Tech Tuesday - Mastering Time Management Unlock the Power of OnePlan's Timesh...
 
How To Manage Restaurant Staff -BTRESTRO
How To Manage Restaurant Staff -BTRESTROHow To Manage Restaurant Staff -BTRESTRO
How To Manage Restaurant Staff -BTRESTRO
 
Open Source Summit NA 2024: Open Source Cloud Costs - OpenCost's Impact on En...
Open Source Summit NA 2024: Open Source Cloud Costs - OpenCost's Impact on En...Open Source Summit NA 2024: Open Source Cloud Costs - OpenCost's Impact on En...
Open Source Summit NA 2024: Open Source Cloud Costs - OpenCost's Impact on En...
 
20240415 [Container Plumbing Days] Usernetes Gen2 - Kubernetes in Rootless Do...
20240415 [Container Plumbing Days] Usernetes Gen2 - Kubernetes in Rootless Do...20240415 [Container Plumbing Days] Usernetes Gen2 - Kubernetes in Rootless Do...
20240415 [Container Plumbing Days] Usernetes Gen2 - Kubernetes in Rootless Do...
 
Introduction Computer Science - Software Design.pdf
Introduction Computer Science - Software Design.pdfIntroduction Computer Science - Software Design.pdf
Introduction Computer Science - Software Design.pdf
 
Hot Sexy call girls in Patel Nagar🔝 9953056974 🔝 escort Service
Hot Sexy call girls in Patel Nagar🔝 9953056974 🔝 escort ServiceHot Sexy call girls in Patel Nagar🔝 9953056974 🔝 escort Service
Hot Sexy call girls in Patel Nagar🔝 9953056974 🔝 escort Service
 
Software Project Health Check: Best Practices and Techniques for Your Product...
Software Project Health Check: Best Practices and Techniques for Your Product...Software Project Health Check: Best Practices and Techniques for Your Product...
Software Project Health Check: Best Practices and Techniques for Your Product...
 
Salesforce Implementation Services PPT By ABSYZ
Salesforce Implementation Services PPT By ABSYZSalesforce Implementation Services PPT By ABSYZ
Salesforce Implementation Services PPT By ABSYZ
 
Recruitment Management Software Benefits (Infographic)
Recruitment Management Software Benefits (Infographic)Recruitment Management Software Benefits (Infographic)
Recruitment Management Software Benefits (Infographic)
 
Taming Distributed Systems: Key Insights from Wix's Large-Scale Experience - ...
Taming Distributed Systems: Key Insights from Wix's Large-Scale Experience - ...Taming Distributed Systems: Key Insights from Wix's Large-Scale Experience - ...
Taming Distributed Systems: Key Insights from Wix's Large-Scale Experience - ...
 
How to submit a standout Adobe Champion Application
How to submit a standout Adobe Champion ApplicationHow to submit a standout Adobe Champion Application
How to submit a standout Adobe Champion Application
 
MYjobs Presentation Django-based project
MYjobs Presentation Django-based projectMYjobs Presentation Django-based project
MYjobs Presentation Django-based project
 
Implementing Zero Trust strategy with Azure
Implementing Zero Trust strategy with AzureImplementing Zero Trust strategy with Azure
Implementing Zero Trust strategy with Azure
 
UI5ers live - Custom Controls wrapping 3rd-party libs.pptx
UI5ers live - Custom Controls wrapping 3rd-party libs.pptxUI5ers live - Custom Controls wrapping 3rd-party libs.pptx
UI5ers live - Custom Controls wrapping 3rd-party libs.pptx
 
Balasore Best It Company|| Top 10 IT Company || Balasore Software company Odisha
Balasore Best It Company|| Top 10 IT Company || Balasore Software company OdishaBalasore Best It Company|| Top 10 IT Company || Balasore Software company Odisha
Balasore Best It Company|| Top 10 IT Company || Balasore Software company Odisha
 

C# Type System Overview

  • 1.
  • 2. Type System Anoop K. C. anoop@baabte.com www.facebook.com/anoopb aabte twitter.com/anoop_baabte in.linkedin.com/in/anoopbaa bte/ +91 9746854752
  • 3. C# is a strongly-typed language. Every variable and constant has a type, as does every expression that evaluates to a value. The information stored in a type can include the following: The storage space that a variable of the type requires The maximum and minimum values that it can represent. The members (methods, fields, events, and so on) that it contains. The base type it inherits from. The location where the memory for variables will be allocated at run time. The kinds of operations that are permitted.
  • 4. Example The compiler uses type information to make sure that all operations that are performed in your code are type safe. For example, if you declare a variable of type int, the compiler allows you to use the variable in addition and subtraction operations. If you try to perform those same operations on a variable of type bool, the compiler generates an error, as shown in the following example: When we declare a variable or constant in a program, we must either specify its type or use the var keyword to let the compiler infer the type.
  • 5. After a variable is declared, it cannot be re-declared with a new type, and it cannot be assigned a value that is not compatible with its declared type. For example, you cannot declare an int and then assign it a Boolean value of true. However, values can be converted to other types, when they are assigned to new variables or passed as method arguments. A type conversion that does not cause data loss is performed automatically by the compiler. A conversion that might cause data loss requires a cast in the source code.
  • 6. Built-in Types C# provides a standard set of built-in numeric types to represent integers, floating point values, Boolean expressions, text characters, decimal values, and other types of data. integers floating point values Boolean expressions text characters decimal values & other types of data. There are also built-in string and object types. These are available to use in any C# program
  • 7. Custom Types We use the struct, class, interface, and enum constructs to create our own custom types. By default, the most frequently used types in the class library are available in any C# program. Others become available only when we explicitly add a project reference to the assembly in which they are defined. After the compiler has a reference to the assembly, we can declare variables (and constants) of the types declared in that assembly in source code.
  • 8. The common type system It is important to understand two fundamental points about the type system in the .NET Framework: It supports the principle of inheritance, that means, types can derive from other types, called base types. All types derive ultimately from a single base type, which is System.Object (C# keyword: object). This unified type hierarchy is called the Common Type System (CTS). Each type in the CTS is defined as either a value type or a reference type. •Types that you define by using the struct keyword are value types •Types that you define by using the class keyword are reference types Reference types and value types have different compile-time rules, and different run-time behavior.
  • 9. Value types Value type variables directly contain their values the memory is allocated inline in whatever context the variable is declared There is no separate heap allocation or garbage collection overhead for value- type variables. There are two categories of value types: struct and enum. Value types are sealed, that means they does not allow inheritance
  • 10. Reference types A type that is defined as a class, delegate, array, or interface is a reference type. At run time, when we declare a variable of a reference type, the variable contains the value null until we explicitly create an instance of the object by using the new operator, or assign it an object that has been created elsewhere by using new When a reference type variable is created, the memory is allocated on the managed heap, and the variable holds only a reference to the location of the object. All arrays are reference types, even if their elements are value types. Reference types fully support inheritance.
  • 11. Generic types A type which is declared with one or more type parameters that serve as a placeholder for the actual type (the concrete type) that client code will provide when it creates an instance of the type. For example, the .NET Framework type System.Collections.Generic.List<T> has one type parameter that by convention is given the name T. When you create an instance of the type, you specify the type of the objects that the list will contain, for example, string: List<string> strings = new List<string>(); The use of the type parameter makes it possible to reuse the same class to hold any type of element Generic collection types are strongly typed
  • 12. Implicit Types, Anonymous Types, and Nullable Types We can implicitly type a local variable (but not class members) by using the var keyword. The variable still receives a type at compile time, but the type is provided by the compiler. Anonymous types are types those have scope only inside the method in which they are defined. The compiler itself will create an arbitrary class for such types, giving us the advantage of not having to define a class for a type that is only used inside a single method. Anonymous types are immutable. Anonymous types provide a convenient way to encapsulate a set of read-only properties into a single object without having to explicitly define a type first. The type name is generated by the compiler and is not available at the source code level. The type of each property is inferred by the compiler. Ordinary value types cannot have a value of null. we can create nullable value types by affixing a ? after the type. For example, int? is an int type that can also have the value null.
  • 13. Follow us @ twitter.com/baabtra Like us @ facebook.com/baabtra Subscribe to us @ youtube.com/baabtra Become a follower @ slideshare.net/BaabtraMentoringPartner Connect to us @ in.linkedin.com/in/baabtra Thanks in advance. www.baabtra.com | www.massbaab.com |www.baabte.com
  • 14. Contact Us Emarald Mall (Big Bazar Building) Mavoor Road, Kozhikode, Kerala, India. Ph: + 91 – 495 40 25 550 NC Complex, Near Bus Stand Mukkam, Kozhikode, Kerala, India. Ph: + 91 – 495 40 25 550 Cafit Square, Hilite Business Park, Near Pantheerankavu, Kozhikode Start up Village Eranakulam, Kerala, India. Email: info@baabtra.com