SlideShare a Scribd company logo
1 of 9
Lesson 9
Learn C#. Series of C# lessons
http://csharp.honcharuk.me/lesson-9
Agenda
• DateTime, DateTimeOffset and TimeSpan
• TimeZone and TimeZoneInfo
• Equality Comparison
• ICloneable
DateTime, DateTimeOffset and TimeSpan
• DateTime and DateTimeOffset are immutable structs for representing a date, and optionally, a
time. They have a resolution of 100 ns and a range covering the years 0001 through 9999
• DateTimeOffset was added in Framework 3.5 and is functionally similar to DateTime. Its
distinguishing feature is that it also stores a UTC offset; this allows more meaningful results when
comparing values across different time zones.
• TimeSpan Represents a time interval.
TimeZone and TimeZoneInfo
• The TimeZone and TimeZoneInfo classes provide information on time zone names UTC offsets,
and daylight saving time rules. TimeZoneInfo is the more powerful of the two and was introduced
in Framework 3.5
• The biggest difference between the two types is that TimeZone lets you access the current local
time zone, whereas TimeZoneInfo provides access to all the world’s time zones. Further,
TimeZoneInfo exposes a richer (although at times, more awkward) rules-based model for
describing daylight saving time
var bangkokTime = TimeZoneInfo.ConvertTime(DateTime.Now, TimeZoneInfo.FindSystemTimeZoneById("SE Asia Standard Time"));
Console.WriteLine("Loca time in Bangkok is: {0}", bangkokTime);
Equality Comparison
• Value equality: two values are equivalent in some sense
• Referential equality: two references refer to exactly the same object
int x = 5, y = 5;
Console.WriteLine(x == y);
A a1 = new A {N = 5};
A a2 = new A { N = 5 };
Console.WriteLine(a1 == a2); // False
a1 = a2;
Console.WriteLine(a1 == a2); // True
Equals
• null-safe equality comparison
• The double type’s == operator enforces that one NaN can never equal anything else — even
another NaN. This is most natural from a mathematical perspective, and it reflects the underlying
CPU behavior
var sb1 = new StringBuilder("foo");
var sb2 = new StringBuilder("foo");
Console.WriteLine(sb1 == sb2); // False (referential equality)
Console.WriteLine(sb1.Equals(sb2)); // True (value equality)
object x = 3, y = 3;
Console.WriteLine(object.Equals(x, y)); // True
x = null;
Console.WriteLine(object.Equals(x, y)); // False
y = null;
Console.WriteLine(object.Equals(x, y)); // True
Override Equals
class A
{
public int N { get; set; }
public bool Equals(A obj)
{
return obj.N == N;
}
public override bool Equals(object obj)
{
return ((A)obj).N == N;
}
}
A a1 = new A { N = 5 };
A a2 = new A { N = 5 };
Console.WriteLine(a1.Equals((object)a2));
ICloneable
class Book: ICloneable
{
public string Author { get; set; }
public string Title { get; set; }
public object Clone()
{
return new Book
{
Author = Author,
Title = Title
};
}
}
Book b1 = new Book
{
Author = "Tom",
Title = "Adventures"
};
Book b2 = (Book)b1.Clone();
Thank you!
Questions?

More Related Content

What's hot

SI report klied
SI report kliedSI report klied
SI report kliedkliederica
 
Map reduce (from Google)
Map reduce (from Google)Map reduce (from Google)
Map reduce (from Google)Sri Prasanna
 
3D Analyst - Lake, Jatiluhur
3D Analyst - Lake, Jatiluhur3D Analyst - Lake, Jatiluhur
3D Analyst - Lake, JatiluhurHartanto Sanjaya
 
Finding Top-k Dominance on Incomplete Big Data Using MapReduce Framework
Finding Top-k Dominance on Incomplete Big Data Using MapReduce FrameworkFinding Top-k Dominance on Incomplete Big Data Using MapReduce Framework
Finding Top-k Dominance on Incomplete Big Data Using MapReduce FrameworkNavid Kalaei
 
Modeling Count-based Raster Data with ArcGIS and R
Modeling Count-based Raster Data with ArcGIS and RModeling Count-based Raster Data with ArcGIS and R
Modeling Count-based Raster Data with ArcGIS and RAzavea
 
ICML 2016: The Information Sieve
ICML 2016: The Information SieveICML 2016: The Information Sieve
ICML 2016: The Information Sievegregv123
 
3D Analyst - Watershed, Padang
3D Analyst - Watershed, Padang3D Analyst - Watershed, Padang
3D Analyst - Watershed, PadangHartanto Sanjaya
 
Cmis 102 hands on/tutorialoutlet
Cmis 102 hands on/tutorialoutletCmis 102 hands on/tutorialoutlet
Cmis 102 hands on/tutorialoutletPoppinss
 
Jan13 Boards
Jan13 BoardsJan13 Boards
Jan13 Boardsyukondawn
 
3D Analyst Watershed Lombok
3D Analyst Watershed  Lombok3D Analyst Watershed  Lombok
3D Analyst Watershed LombokHartanto Sanjaya
 
Final Presentation-DATNYC
Final Presentation-DATNYCFinal Presentation-DATNYC
Final Presentation-DATNYCKaren Zellner
 
poster-hadoop-MiroslavMihaylov
poster-hadoop-MiroslavMihaylovposter-hadoop-MiroslavMihaylov
poster-hadoop-MiroslavMihaylovMiroslav Mihaylov
 
MapMap-Reduce recipes in with c#
MapMap-Reduce recipes in with c#MapMap-Reduce recipes in with c#
MapMap-Reduce recipes in with c#Erik Lebel
 
Count downlatch & implementation
Count downlatch & implementationCount downlatch & implementation
Count downlatch & implementationIsaac Liao
 

What's hot (20)

SI report klied
SI report kliedSI report klied
SI report klied
 
Map reduce (from Google)
Map reduce (from Google)Map reduce (from Google)
Map reduce (from Google)
 
Data structure Stack
Data structure StackData structure Stack
Data structure Stack
 
3D Analyst - Lake, Jatiluhur
3D Analyst - Lake, Jatiluhur3D Analyst - Lake, Jatiluhur
3D Analyst - Lake, Jatiluhur
 
Finding Top-k Dominance on Incomplete Big Data Using MapReduce Framework
Finding Top-k Dominance on Incomplete Big Data Using MapReduce FrameworkFinding Top-k Dominance on Incomplete Big Data Using MapReduce Framework
Finding Top-k Dominance on Incomplete Big Data Using MapReduce Framework
 
Modeling Count-based Raster Data with ArcGIS and R
Modeling Count-based Raster Data with ArcGIS and RModeling Count-based Raster Data with ArcGIS and R
Modeling Count-based Raster Data with ArcGIS and R
 
ICML 2016: The Information Sieve
ICML 2016: The Information SieveICML 2016: The Information Sieve
ICML 2016: The Information Sieve
 
3D Analyst - Watershed, Padang
3D Analyst - Watershed, Padang3D Analyst - Watershed, Padang
3D Analyst - Watershed, Padang
 
Cmis 102 hands on/tutorialoutlet
Cmis 102 hands on/tutorialoutletCmis 102 hands on/tutorialoutlet
Cmis 102 hands on/tutorialoutlet
 
Jan13 Boards
Jan13 BoardsJan13 Boards
Jan13 Boards
 
Stack a Data Structure
Stack a Data StructureStack a Data Structure
Stack a Data Structure
 
3D Analyst Watershed Lombok
3D Analyst Watershed  Lombok3D Analyst Watershed  Lombok
3D Analyst Watershed Lombok
 
Stack & queue
Stack & queueStack & queue
Stack & queue
 
Final Presentation-DATNYC
Final Presentation-DATNYCFinal Presentation-DATNYC
Final Presentation-DATNYC
 
poster-hadoop-MiroslavMihaylov
poster-hadoop-MiroslavMihaylovposter-hadoop-MiroslavMihaylov
poster-hadoop-MiroslavMihaylov
 
R nonlinear least square
R   nonlinear least squareR   nonlinear least square
R nonlinear least square
 
Counting sort
Counting sortCounting sort
Counting sort
 
MapMap-Reduce recipes in with c#
MapMap-Reduce recipes in with c#MapMap-Reduce recipes in with c#
MapMap-Reduce recipes in with c#
 
Matlab integration
Matlab integrationMatlab integration
Matlab integration
 
Count downlatch & implementation
Count downlatch & implementationCount downlatch & implementation
Count downlatch & implementation
 

Similar to Lesson9

A peek on numerical programming in perl and python e christopher dyken 2005
A peek on numerical programming in perl and python  e christopher dyken  2005A peek on numerical programming in perl and python  e christopher dyken  2005
A peek on numerical programming in perl and python e christopher dyken 2005Jules Krdenas
 
If You Think You Can Stay Away from Functional Programming, You Are Wrong
If You Think You Can Stay Away from Functional Programming, You Are WrongIf You Think You Can Stay Away from Functional Programming, You Are Wrong
If You Think You Can Stay Away from Functional Programming, You Are WrongMario Fusco
 
JavaScript Editions ES7, ES8 and ES9 vs V8
JavaScript Editions ES7, ES8 and ES9 vs V8JavaScript Editions ES7, ES8 and ES9 vs V8
JavaScript Editions ES7, ES8 and ES9 vs V8Rafael Casuso Romate
 
C# 101: Intro to Programming with C#
C# 101: Intro to Programming with C#C# 101: Intro to Programming with C#
C# 101: Intro to Programming with C#Hawkman Academy
 
Building data fusion surrogate models for spacecraft aerodynamic problems wit...
Building data fusion surrogate models for spacecraft aerodynamic problems wit...Building data fusion surrogate models for spacecraft aerodynamic problems wit...
Building data fusion surrogate models for spacecraft aerodynamic problems wit...Shinwoo Jang
 
K is for Kotlin
K is for KotlinK is for Kotlin
K is for KotlinTechMagic
 
Functional Programming You Already Know
Functional Programming You Already KnowFunctional Programming You Already Know
Functional Programming You Already KnowKevlin Henney
 
Introduction to data structures and complexity.pptx
Introduction to data structures and complexity.pptxIntroduction to data structures and complexity.pptx
Introduction to data structures and complexity.pptxPJS KUMAR
 
The Ring programming language version 1.4.1 book - Part 29 of 31
The Ring programming language version 1.4.1 book - Part 29 of 31The Ring programming language version 1.4.1 book - Part 29 of 31
The Ring programming language version 1.4.1 book - Part 29 of 31Mahmoud Samir Fayed
 
Lecture 5: Functional Programming
Lecture 5: Functional ProgrammingLecture 5: Functional Programming
Lecture 5: Functional ProgrammingEelco Visser
 
C++ Interview Question And Answer
C++ Interview Question And AnswerC++ Interview Question And Answer
C++ Interview Question And AnswerJagan Mohan Bishoyi
 
C++ questions And Answer
C++ questions And AnswerC++ questions And Answer
C++ questions And Answerlavparmar007
 
Nagios Conference 2014 - Rob Seiwert - Graphing and Trend Prediction in Nagios
Nagios Conference 2014 - Rob Seiwert - Graphing and Trend Prediction in NagiosNagios Conference 2014 - Rob Seiwert - Graphing and Trend Prediction in Nagios
Nagios Conference 2014 - Rob Seiwert - Graphing and Trend Prediction in NagiosNagios
 
Maclennan chap5-pascal
Maclennan chap5-pascalMaclennan chap5-pascal
Maclennan chap5-pascalSerghei Urban
 
Algorithm Complexity and Main Concepts
Algorithm Complexity and Main ConceptsAlgorithm Complexity and Main Concepts
Algorithm Complexity and Main ConceptsAdelina Ahadova
 

Similar to Lesson9 (20)

A peek on numerical programming in perl and python e christopher dyken 2005
A peek on numerical programming in perl and python  e christopher dyken  2005A peek on numerical programming in perl and python  e christopher dyken  2005
A peek on numerical programming in perl and python e christopher dyken 2005
 
If You Think You Can Stay Away from Functional Programming, You Are Wrong
If You Think You Can Stay Away from Functional Programming, You Are WrongIf You Think You Can Stay Away from Functional Programming, You Are Wrong
If You Think You Can Stay Away from Functional Programming, You Are Wrong
 
JavaScript Editions ES7, ES8 and ES9 vs V8
JavaScript Editions ES7, ES8 and ES9 vs V8JavaScript Editions ES7, ES8 and ES9 vs V8
JavaScript Editions ES7, ES8 and ES9 vs V8
 
C# 101: Intro to Programming with C#
C# 101: Intro to Programming with C#C# 101: Intro to Programming with C#
C# 101: Intro to Programming with C#
 
Building data fusion surrogate models for spacecraft aerodynamic problems wit...
Building data fusion surrogate models for spacecraft aerodynamic problems wit...Building data fusion surrogate models for spacecraft aerodynamic problems wit...
Building data fusion surrogate models for spacecraft aerodynamic problems wit...
 
K is for Kotlin
K is for KotlinK is for Kotlin
K is for Kotlin
 
Functional Programming You Already Know
Functional Programming You Already KnowFunctional Programming You Already Know
Functional Programming You Already Know
 
Introduction to data structures and complexity.pptx
Introduction to data structures and complexity.pptxIntroduction to data structures and complexity.pptx
Introduction to data structures and complexity.pptx
 
The Ring programming language version 1.4.1 book - Part 29 of 31
The Ring programming language version 1.4.1 book - Part 29 of 31The Ring programming language version 1.4.1 book - Part 29 of 31
The Ring programming language version 1.4.1 book - Part 29 of 31
 
Lecture 5: Functional Programming
Lecture 5: Functional ProgrammingLecture 5: Functional Programming
Lecture 5: Functional Programming
 
Big O Notation
Big O NotationBig O Notation
Big O Notation
 
C++ Interview Question And Answer
C++ Interview Question And AnswerC++ Interview Question And Answer
C++ Interview Question And Answer
 
C++ questions And Answer
C++ questions And AnswerC++ questions And Answer
C++ questions And Answer
 
C++ Language
C++ LanguageC++ Language
C++ Language
 
Advanced JavaScript
Advanced JavaScript Advanced JavaScript
Advanced JavaScript
 
Nagios Conference 2014 - Rob Seiwert - Graphing and Trend Prediction in Nagios
Nagios Conference 2014 - Rob Seiwert - Graphing and Trend Prediction in NagiosNagios Conference 2014 - Rob Seiwert - Graphing and Trend Prediction in Nagios
Nagios Conference 2014 - Rob Seiwert - Graphing and Trend Prediction in Nagios
 
Maclennan chap5-pascal
Maclennan chap5-pascalMaclennan chap5-pascal
Maclennan chap5-pascal
 
Function overloading
Function overloadingFunction overloading
Function overloading
 
Functional programming
Functional programmingFunctional programming
Functional programming
 
Algorithm Complexity and Main Concepts
Algorithm Complexity and Main ConceptsAlgorithm Complexity and Main Concepts
Algorithm Complexity and Main Concepts
 

More from Alex Honcharuk (8)

Lesson11
Lesson11Lesson11
Lesson11
 
Lesson 10
Lesson 10Lesson 10
Lesson 10
 
Lesson8
Lesson8Lesson8
Lesson8
 
Lesson6
Lesson6Lesson6
Lesson6
 
Lesson5
Lesson5Lesson5
Lesson5
 
Lesson 4
Lesson 4Lesson 4
Lesson 4
 
Lesson2
Lesson2Lesson2
Lesson2
 
Lesson1
Lesson1Lesson1
Lesson1
 

Recently uploaded

XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXssuser89054b
 
Introduction to Serverless with AWS Lambda
Introduction to Serverless with AWS LambdaIntroduction to Serverless with AWS Lambda
Introduction to Serverless with AWS LambdaOmar Fathy
 
VIP Call Girls Palanpur 7001035870 Whatsapp Number, 24/07 Booking
VIP Call Girls Palanpur 7001035870 Whatsapp Number, 24/07 BookingVIP Call Girls Palanpur 7001035870 Whatsapp Number, 24/07 Booking
VIP Call Girls Palanpur 7001035870 Whatsapp Number, 24/07 Bookingdharasingh5698
 
Minimum and Maximum Modes of microprocessor 8086
Minimum and Maximum Modes of microprocessor 8086Minimum and Maximum Modes of microprocessor 8086
Minimum and Maximum Modes of microprocessor 8086anil_gaur
 
chapter 5.pptx: drainage and irrigation engineering
chapter 5.pptx: drainage and irrigation engineeringchapter 5.pptx: drainage and irrigation engineering
chapter 5.pptx: drainage and irrigation engineeringmulugeta48
 
22-prompt engineering noted slide shown.pdf
22-prompt engineering noted slide shown.pdf22-prompt engineering noted slide shown.pdf
22-prompt engineering noted slide shown.pdf203318pmpc
 
Hostel management system project report..pdf
Hostel management system project report..pdfHostel management system project report..pdf
Hostel management system project report..pdfKamal Acharya
 
Thermal Engineering -unit - III & IV.ppt
Thermal Engineering -unit - III & IV.pptThermal Engineering -unit - III & IV.ppt
Thermal Engineering -unit - III & IV.pptDineshKumar4165
 
University management System project report..pdf
University management System project report..pdfUniversity management System project report..pdf
University management System project report..pdfKamal Acharya
 
VIP Call Girls Ankleshwar 7001035870 Whatsapp Number, 24/07 Booking
VIP Call Girls Ankleshwar 7001035870 Whatsapp Number, 24/07 BookingVIP Call Girls Ankleshwar 7001035870 Whatsapp Number, 24/07 Booking
VIP Call Girls Ankleshwar 7001035870 Whatsapp Number, 24/07 Bookingdharasingh5698
 
KubeKraft presentation @CloudNativeHooghly
KubeKraft presentation @CloudNativeHooghlyKubeKraft presentation @CloudNativeHooghly
KubeKraft presentation @CloudNativeHooghlysanyuktamishra911
 
Bhosari ( Call Girls ) Pune 6297143586 Hot Model With Sexy Bhabi Ready For ...
Bhosari ( Call Girls ) Pune  6297143586  Hot Model With Sexy Bhabi Ready For ...Bhosari ( Call Girls ) Pune  6297143586  Hot Model With Sexy Bhabi Ready For ...
Bhosari ( Call Girls ) Pune 6297143586 Hot Model With Sexy Bhabi Ready For ...tanu pandey
 
Top Rated Call Girls In chittoor 📱 {7001035870} VIP Escorts chittoor
Top Rated Call Girls In chittoor 📱 {7001035870} VIP Escorts chittoorTop Rated Call Girls In chittoor 📱 {7001035870} VIP Escorts chittoor
Top Rated Call Girls In chittoor 📱 {7001035870} VIP Escorts chittoordharasingh5698
 
Call Girls Wakad Call Me 7737669865 Budget Friendly No Advance Booking
Call Girls Wakad Call Me 7737669865 Budget Friendly No Advance BookingCall Girls Wakad Call Me 7737669865 Budget Friendly No Advance Booking
Call Girls Wakad Call Me 7737669865 Budget Friendly No Advance Bookingroncy bisnoi
 
Unleashing the Power of the SORA AI lastest leap
Unleashing the Power of the SORA AI lastest leapUnleashing the Power of the SORA AI lastest leap
Unleashing the Power of the SORA AI lastest leapRishantSharmaFr
 
Thermal Engineering Unit - I & II . ppt
Thermal Engineering  Unit - I & II . pptThermal Engineering  Unit - I & II . ppt
Thermal Engineering Unit - I & II . pptDineshKumar4165
 

Recently uploaded (20)

XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
 
Introduction to Serverless with AWS Lambda
Introduction to Serverless with AWS LambdaIntroduction to Serverless with AWS Lambda
Introduction to Serverless with AWS Lambda
 
VIP Call Girls Palanpur 7001035870 Whatsapp Number, 24/07 Booking
VIP Call Girls Palanpur 7001035870 Whatsapp Number, 24/07 BookingVIP Call Girls Palanpur 7001035870 Whatsapp Number, 24/07 Booking
VIP Call Girls Palanpur 7001035870 Whatsapp Number, 24/07 Booking
 
Minimum and Maximum Modes of microprocessor 8086
Minimum and Maximum Modes of microprocessor 8086Minimum and Maximum Modes of microprocessor 8086
Minimum and Maximum Modes of microprocessor 8086
 
chapter 5.pptx: drainage and irrigation engineering
chapter 5.pptx: drainage and irrigation engineeringchapter 5.pptx: drainage and irrigation engineering
chapter 5.pptx: drainage and irrigation engineering
 
22-prompt engineering noted slide shown.pdf
22-prompt engineering noted slide shown.pdf22-prompt engineering noted slide shown.pdf
22-prompt engineering noted slide shown.pdf
 
Call Girls in Ramesh Nagar Delhi 💯 Call Us 🔝9953056974 🔝 Escort Service
Call Girls in Ramesh Nagar Delhi 💯 Call Us 🔝9953056974 🔝 Escort ServiceCall Girls in Ramesh Nagar Delhi 💯 Call Us 🔝9953056974 🔝 Escort Service
Call Girls in Ramesh Nagar Delhi 💯 Call Us 🔝9953056974 🔝 Escort Service
 
Hostel management system project report..pdf
Hostel management system project report..pdfHostel management system project report..pdf
Hostel management system project report..pdf
 
Thermal Engineering -unit - III & IV.ppt
Thermal Engineering -unit - III & IV.pptThermal Engineering -unit - III & IV.ppt
Thermal Engineering -unit - III & IV.ppt
 
University management System project report..pdf
University management System project report..pdfUniversity management System project report..pdf
University management System project report..pdf
 
VIP Call Girls Ankleshwar 7001035870 Whatsapp Number, 24/07 Booking
VIP Call Girls Ankleshwar 7001035870 Whatsapp Number, 24/07 BookingVIP Call Girls Ankleshwar 7001035870 Whatsapp Number, 24/07 Booking
VIP Call Girls Ankleshwar 7001035870 Whatsapp Number, 24/07 Booking
 
KubeKraft presentation @CloudNativeHooghly
KubeKraft presentation @CloudNativeHooghlyKubeKraft presentation @CloudNativeHooghly
KubeKraft presentation @CloudNativeHooghly
 
(INDIRA) Call Girl Aurangabad Call Now 8617697112 Aurangabad Escorts 24x7
(INDIRA) Call Girl Aurangabad Call Now 8617697112 Aurangabad Escorts 24x7(INDIRA) Call Girl Aurangabad Call Now 8617697112 Aurangabad Escorts 24x7
(INDIRA) Call Girl Aurangabad Call Now 8617697112 Aurangabad Escorts 24x7
 
Bhosari ( Call Girls ) Pune 6297143586 Hot Model With Sexy Bhabi Ready For ...
Bhosari ( Call Girls ) Pune  6297143586  Hot Model With Sexy Bhabi Ready For ...Bhosari ( Call Girls ) Pune  6297143586  Hot Model With Sexy Bhabi Ready For ...
Bhosari ( Call Girls ) Pune 6297143586 Hot Model With Sexy Bhabi Ready For ...
 
Top Rated Call Girls In chittoor 📱 {7001035870} VIP Escorts chittoor
Top Rated Call Girls In chittoor 📱 {7001035870} VIP Escorts chittoorTop Rated Call Girls In chittoor 📱 {7001035870} VIP Escorts chittoor
Top Rated Call Girls In chittoor 📱 {7001035870} VIP Escorts chittoor
 
Call Girls Wakad Call Me 7737669865 Budget Friendly No Advance Booking
Call Girls Wakad Call Me 7737669865 Budget Friendly No Advance BookingCall Girls Wakad Call Me 7737669865 Budget Friendly No Advance Booking
Call Girls Wakad Call Me 7737669865 Budget Friendly No Advance Booking
 
(INDIRA) Call Girl Meerut Call Now 8617697112 Meerut Escorts 24x7
(INDIRA) Call Girl Meerut Call Now 8617697112 Meerut Escorts 24x7(INDIRA) Call Girl Meerut Call Now 8617697112 Meerut Escorts 24x7
(INDIRA) Call Girl Meerut Call Now 8617697112 Meerut Escorts 24x7
 
(INDIRA) Call Girl Bhosari Call Now 8617697112 Bhosari Escorts 24x7
(INDIRA) Call Girl Bhosari Call Now 8617697112 Bhosari Escorts 24x7(INDIRA) Call Girl Bhosari Call Now 8617697112 Bhosari Escorts 24x7
(INDIRA) Call Girl Bhosari Call Now 8617697112 Bhosari Escorts 24x7
 
Unleashing the Power of the SORA AI lastest leap
Unleashing the Power of the SORA AI lastest leapUnleashing the Power of the SORA AI lastest leap
Unleashing the Power of the SORA AI lastest leap
 
Thermal Engineering Unit - I & II . ppt
Thermal Engineering  Unit - I & II . pptThermal Engineering  Unit - I & II . ppt
Thermal Engineering Unit - I & II . ppt
 

Lesson9

  • 1. Lesson 9 Learn C#. Series of C# lessons http://csharp.honcharuk.me/lesson-9
  • 2. Agenda • DateTime, DateTimeOffset and TimeSpan • TimeZone and TimeZoneInfo • Equality Comparison • ICloneable
  • 3. DateTime, DateTimeOffset and TimeSpan • DateTime and DateTimeOffset are immutable structs for representing a date, and optionally, a time. They have a resolution of 100 ns and a range covering the years 0001 through 9999 • DateTimeOffset was added in Framework 3.5 and is functionally similar to DateTime. Its distinguishing feature is that it also stores a UTC offset; this allows more meaningful results when comparing values across different time zones. • TimeSpan Represents a time interval.
  • 4. TimeZone and TimeZoneInfo • The TimeZone and TimeZoneInfo classes provide information on time zone names UTC offsets, and daylight saving time rules. TimeZoneInfo is the more powerful of the two and was introduced in Framework 3.5 • The biggest difference between the two types is that TimeZone lets you access the current local time zone, whereas TimeZoneInfo provides access to all the world’s time zones. Further, TimeZoneInfo exposes a richer (although at times, more awkward) rules-based model for describing daylight saving time var bangkokTime = TimeZoneInfo.ConvertTime(DateTime.Now, TimeZoneInfo.FindSystemTimeZoneById("SE Asia Standard Time")); Console.WriteLine("Loca time in Bangkok is: {0}", bangkokTime);
  • 5. Equality Comparison • Value equality: two values are equivalent in some sense • Referential equality: two references refer to exactly the same object int x = 5, y = 5; Console.WriteLine(x == y); A a1 = new A {N = 5}; A a2 = new A { N = 5 }; Console.WriteLine(a1 == a2); // False a1 = a2; Console.WriteLine(a1 == a2); // True
  • 6. Equals • null-safe equality comparison • The double type’s == operator enforces that one NaN can never equal anything else — even another NaN. This is most natural from a mathematical perspective, and it reflects the underlying CPU behavior var sb1 = new StringBuilder("foo"); var sb2 = new StringBuilder("foo"); Console.WriteLine(sb1 == sb2); // False (referential equality) Console.WriteLine(sb1.Equals(sb2)); // True (value equality) object x = 3, y = 3; Console.WriteLine(object.Equals(x, y)); // True x = null; Console.WriteLine(object.Equals(x, y)); // False y = null; Console.WriteLine(object.Equals(x, y)); // True
  • 7. Override Equals class A { public int N { get; set; } public bool Equals(A obj) { return obj.N == N; } public override bool Equals(object obj) { return ((A)obj).N == N; } } A a1 = new A { N = 5 }; A a2 = new A { N = 5 }; Console.WriteLine(a1.Equals((object)a2));
  • 8. ICloneable class Book: ICloneable { public string Author { get; set; } public string Title { get; set; } public object Clone() { return new Book { Author = Author, Title = Title }; } } Book b1 = new Book { Author = "Tom", Title = "Adventures" }; Book b2 = (Book)b1.Clone();

Editor's Notes

  1. http://stackoverflow.com/questions/4331189/datetime-vs-datetimeoffset https://msdn.microsoft.com/en-us/library/system.timespan(v=vs.110).aspx