Submit Search
Upload
C# Tutorial MSM_Murach chapter-09-slides
•
Download as PPT, PDF
•
0 likes
•
303 views
S
Sami Mut
Follow
C# Tutorial MSM_Murach chapter-09-slides ////............................//
Read less
Read more
Technology
Report
Share
Report
Share
1 of 44
Download now
Recommended
C# Tutorial MSM_Murach chapter-13-slides
C# Tutorial MSM_Murach chapter-13-slides
Sami Mut
C# Tutorial MSM_Murach chapter-12-slides
C# Tutorial MSM_Murach chapter-12-slides
Sami Mut
C# Tutorial MSM_Murach chapter-23-slides
C# Tutorial MSM_Murach chapter-23-slides
Sami Mut
C# Tutorial MSM_Murach chapter-24-slides
C# Tutorial MSM_Murach chapter-24-slides
Sami Mut
C# Tutorial MSM_Murach chapter-08-slides
C# Tutorial MSM_Murach chapter-08-slides
Sami Mut
C# Tutorial MSM_Murach chapter-19-slides
C# Tutorial MSM_Murach chapter-19-slides
Sami Mut
C# Tutorial MSM_Murach chapter-14-slides
C# Tutorial MSM_Murach chapter-14-slides
Sami Mut
C# Tutorial MSM_Murach chapter-05-slides
C# Tutorial MSM_Murach chapter-05-slides
Sami Mut
Recommended
C# Tutorial MSM_Murach chapter-13-slides
C# Tutorial MSM_Murach chapter-13-slides
Sami Mut
C# Tutorial MSM_Murach chapter-12-slides
C# Tutorial MSM_Murach chapter-12-slides
Sami Mut
C# Tutorial MSM_Murach chapter-23-slides
C# Tutorial MSM_Murach chapter-23-slides
Sami Mut
C# Tutorial MSM_Murach chapter-24-slides
C# Tutorial MSM_Murach chapter-24-slides
Sami Mut
C# Tutorial MSM_Murach chapter-08-slides
C# Tutorial MSM_Murach chapter-08-slides
Sami Mut
C# Tutorial MSM_Murach chapter-19-slides
C# Tutorial MSM_Murach chapter-19-slides
Sami Mut
C# Tutorial MSM_Murach chapter-14-slides
C# Tutorial MSM_Murach chapter-14-slides
Sami Mut
C# Tutorial MSM_Murach chapter-05-slides
C# Tutorial MSM_Murach chapter-05-slides
Sami Mut
C# Tutorial MSM_Murach chapter-03-slides
C# Tutorial MSM_Murach chapter-03-slides
Sami Mut
C# Tutorial MSM_Murach chapter-07-slides
C# Tutorial MSM_Murach chapter-07-slides
Sami Mut
C# Tutorial MSM_Murach chapter-15-slides
C# Tutorial MSM_Murach chapter-15-slides
Sami Mut
C# Tutorial MSM_Murach chapter-06-slides
C# Tutorial MSM_Murach chapter-06-slides
Sami Mut
C# Tutorial MSM_Murach chapter-11-slides
C# Tutorial MSM_Murach chapter-11-slides
Sami Mut
C# Tutorial MSM_Murach chapter-04-slides
C# Tutorial MSM_Murach chapter-04-slides
Sami Mut
C# Tutorial MSM_Murach chapter-16-slides
C# Tutorial MSM_Murach chapter-16-slides
Sami Mut
C# Tutorial MSM_Murach chapter-20-slides
C# Tutorial MSM_Murach chapter-20-slides
Sami Mut
C# Tutorial MSM_Murach chapter-02-slides
C# Tutorial MSM_Murach chapter-02-slides
Sami Mut
C# Tutorial MSM_Murach chapter-22-slides
C# Tutorial MSM_Murach chapter-22-slides
Sami Mut
C# Tutorial MSM_Murach chapter-10-slides
C# Tutorial MSM_Murach chapter-10-slides
Sami Mut
Intake 38 9
Intake 38 9
Mahmoud Ouf
Intake 38 8
Intake 38 8
Mahmoud Ouf
Intake 38 7
Intake 38 7
Mahmoud Ouf
Cookbook Oracle SOA Business Rules
Cookbook Oracle SOA Business Rules
Emiel Paasschens
Chapter 2 — Program and Graphical User Interface Design
Chapter 2 — Program and Graphical User Interface Design
francopw
Chapter 08
Chapter 08
llmeade
Content
Content
o3aroo
Chapter 04
Chapter 04
llmeade
FP304 DATABASE SYSTEM PAPER FINAL EXAM AGAIN
FP304 DATABASE SYSTEM PAPER FINAL EXAM AGAIN
Syahriha Ruslan
Computer programming 2 Lesson 14
Computer programming 2 Lesson 14
MLG College of Learning, Inc
Php date & time functions
Php date & time functions
Programmer Blog
More Related Content
What's hot
C# Tutorial MSM_Murach chapter-03-slides
C# Tutorial MSM_Murach chapter-03-slides
Sami Mut
C# Tutorial MSM_Murach chapter-07-slides
C# Tutorial MSM_Murach chapter-07-slides
Sami Mut
C# Tutorial MSM_Murach chapter-15-slides
C# Tutorial MSM_Murach chapter-15-slides
Sami Mut
C# Tutorial MSM_Murach chapter-06-slides
C# Tutorial MSM_Murach chapter-06-slides
Sami Mut
C# Tutorial MSM_Murach chapter-11-slides
C# Tutorial MSM_Murach chapter-11-slides
Sami Mut
C# Tutorial MSM_Murach chapter-04-slides
C# Tutorial MSM_Murach chapter-04-slides
Sami Mut
C# Tutorial MSM_Murach chapter-16-slides
C# Tutorial MSM_Murach chapter-16-slides
Sami Mut
C# Tutorial MSM_Murach chapter-20-slides
C# Tutorial MSM_Murach chapter-20-slides
Sami Mut
C# Tutorial MSM_Murach chapter-02-slides
C# Tutorial MSM_Murach chapter-02-slides
Sami Mut
C# Tutorial MSM_Murach chapter-22-slides
C# Tutorial MSM_Murach chapter-22-slides
Sami Mut
C# Tutorial MSM_Murach chapter-10-slides
C# Tutorial MSM_Murach chapter-10-slides
Sami Mut
Intake 38 9
Intake 38 9
Mahmoud Ouf
Intake 38 8
Intake 38 8
Mahmoud Ouf
Intake 38 7
Intake 38 7
Mahmoud Ouf
Cookbook Oracle SOA Business Rules
Cookbook Oracle SOA Business Rules
Emiel Paasschens
Chapter 2 — Program and Graphical User Interface Design
Chapter 2 — Program and Graphical User Interface Design
francopw
Chapter 08
Chapter 08
llmeade
Content
Content
o3aroo
Chapter 04
Chapter 04
llmeade
FP304 DATABASE SYSTEM PAPER FINAL EXAM AGAIN
FP304 DATABASE SYSTEM PAPER FINAL EXAM AGAIN
Syahriha Ruslan
What's hot
(20)
C# Tutorial MSM_Murach chapter-03-slides
C# Tutorial MSM_Murach chapter-03-slides
C# Tutorial MSM_Murach chapter-07-slides
C# Tutorial MSM_Murach chapter-07-slides
C# Tutorial MSM_Murach chapter-15-slides
C# Tutorial MSM_Murach chapter-15-slides
C# Tutorial MSM_Murach chapter-06-slides
C# Tutorial MSM_Murach chapter-06-slides
C# Tutorial MSM_Murach chapter-11-slides
C# Tutorial MSM_Murach chapter-11-slides
C# Tutorial MSM_Murach chapter-04-slides
C# Tutorial MSM_Murach chapter-04-slides
C# Tutorial MSM_Murach chapter-16-slides
C# Tutorial MSM_Murach chapter-16-slides
C# Tutorial MSM_Murach chapter-20-slides
C# Tutorial MSM_Murach chapter-20-slides
C# Tutorial MSM_Murach chapter-02-slides
C# Tutorial MSM_Murach chapter-02-slides
C# Tutorial MSM_Murach chapter-22-slides
C# Tutorial MSM_Murach chapter-22-slides
C# Tutorial MSM_Murach chapter-10-slides
C# Tutorial MSM_Murach chapter-10-slides
Intake 38 9
Intake 38 9
Intake 38 8
Intake 38 8
Intake 38 7
Intake 38 7
Cookbook Oracle SOA Business Rules
Cookbook Oracle SOA Business Rules
Chapter 2 — Program and Graphical User Interface Design
Chapter 2 — Program and Graphical User Interface Design
Chapter 08
Chapter 08
Content
Content
Chapter 04
Chapter 04
FP304 DATABASE SYSTEM PAPER FINAL EXAM AGAIN
FP304 DATABASE SYSTEM PAPER FINAL EXAM AGAIN
Similar to C# Tutorial MSM_Murach chapter-09-slides
Computer programming 2 Lesson 14
Computer programming 2 Lesson 14
MLG College of Learning, Inc
Php date & time functions
Php date & time functions
Programmer Blog
17 ruby date time
17 ruby date time
Walker Maidana
C# Tutorial MSM_Murach chapter-18-slides
C# Tutorial MSM_Murach chapter-18-slides
Sami Mut
Date and time manipulation
Date and time manipulation
Shahjahan Samoon
Python time
Python time
Janu Jahnavi
C++ Please I am posting the fifth time and hoping to get th.pdf
C++ Please I am posting the fifth time and hoping to get th.pdf
jaipur2
Please I am posting the fifth time and hoping to get this r.pdf
Please I am posting the fifth time and hoping to get this r.pdf
ankit11134
Chapter 16-spreadsheet1 questions and answer
Chapter 16-spreadsheet1 questions and answer
RaajTech
TSQL Functions (SQL Server)
TSQL Functions (SQL Server)
Steve Stedman
Bis 311 final examination answers
Bis 311 final examination answers
RandalHoffman
C programming & data structure [arrays & pointers]
C programming & data structure [arrays & pointers]
MomenMostafa
enum_comp_exercicio01.docx
enum_comp_exercicio01.docx
Michel Valentim
best note.pptx
best note.pptx
DejeneDay
Dates and Times in Java 7 and Java 8
Dates and Times in Java 7 and Java 8
Fulvio Corno
Python datetime
Python datetime
sureshraj43
XP through TDD
XP through TDD
Mauricio Cappella
How to work with dates and times in swift 3
How to work with dates and times in swift 3
allanh0526
in C++ Design a class named Employee The class should keep .pdf
in C++ Design a class named Employee The class should keep .pdf
adithyaups
MS SQL SERVER: Microsoft time series algorithm
MS SQL SERVER: Microsoft time series algorithm
sqlserver content
Similar to C# Tutorial MSM_Murach chapter-09-slides
(20)
Computer programming 2 Lesson 14
Computer programming 2 Lesson 14
Php date & time functions
Php date & time functions
17 ruby date time
17 ruby date time
C# Tutorial MSM_Murach chapter-18-slides
C# Tutorial MSM_Murach chapter-18-slides
Date and time manipulation
Date and time manipulation
Python time
Python time
C++ Please I am posting the fifth time and hoping to get th.pdf
C++ Please I am posting the fifth time and hoping to get th.pdf
Please I am posting the fifth time and hoping to get this r.pdf
Please I am posting the fifth time and hoping to get this r.pdf
Chapter 16-spreadsheet1 questions and answer
Chapter 16-spreadsheet1 questions and answer
TSQL Functions (SQL Server)
TSQL Functions (SQL Server)
Bis 311 final examination answers
Bis 311 final examination answers
C programming & data structure [arrays & pointers]
C programming & data structure [arrays & pointers]
enum_comp_exercicio01.docx
enum_comp_exercicio01.docx
best note.pptx
best note.pptx
Dates and Times in Java 7 and Java 8
Dates and Times in Java 7 and Java 8
Python datetime
Python datetime
XP through TDD
XP through TDD
How to work with dates and times in swift 3
How to work with dates and times in swift 3
in C++ Design a class named Employee The class should keep .pdf
in C++ Design a class named Employee The class should keep .pdf
MS SQL SERVER: Microsoft time series algorithm
MS SQL SERVER: Microsoft time series algorithm
More from Sami Mut
C# Tutorial MSM_Murach chapter-25-slides
C# Tutorial MSM_Murach chapter-25-slides
Sami Mut
C# Tutorial MSM_Murach chapter-21-slides
C# Tutorial MSM_Murach chapter-21-slides
Sami Mut
C# Tutorial MSM_Murach chapter-17-slides
C# Tutorial MSM_Murach chapter-17-slides
Sami Mut
C# Tutorial MSM_Murach chapter-01-slides
C# Tutorial MSM_Murach chapter-01-slides
Sami Mut
MSM_Time
MSM_Time
Sami Mut
chapter 5 Java at rupp cambodia
chapter 5 Java at rupp cambodia
Sami Mut
chapter 2 Java at rupp cambodia
chapter 2 Java at rupp cambodia
Sami Mut
chapter 3 Java at rupp cambodia
chapter 3 Java at rupp cambodia
Sami Mut
chapter 2 Java at rupp cambodia
chapter 2 Java at rupp cambodia
Sami Mut
chapter 1 Java at rupp cambodia
chapter 1 Java at rupp cambodia
Sami Mut
More from Sami Mut
(10)
C# Tutorial MSM_Murach chapter-25-slides
C# Tutorial MSM_Murach chapter-25-slides
C# Tutorial MSM_Murach chapter-21-slides
C# Tutorial MSM_Murach chapter-21-slides
C# Tutorial MSM_Murach chapter-17-slides
C# Tutorial MSM_Murach chapter-17-slides
C# Tutorial MSM_Murach chapter-01-slides
C# Tutorial MSM_Murach chapter-01-slides
MSM_Time
MSM_Time
chapter 5 Java at rupp cambodia
chapter 5 Java at rupp cambodia
chapter 2 Java at rupp cambodia
chapter 2 Java at rupp cambodia
chapter 3 Java at rupp cambodia
chapter 3 Java at rupp cambodia
chapter 2 Java at rupp cambodia
chapter 2 Java at rupp cambodia
chapter 1 Java at rupp cambodia
chapter 1 Java at rupp cambodia
Recently uploaded
Build your next Gen AI Breakthrough - April 2024
Build your next Gen AI Breakthrough - April 2024
Neo4j
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
BookNet Canada
The transition to renewables in India.pdf
The transition to renewables in India.pdf
Competition Advisory Services (India) LLP
APIForce Zurich 5 April Automation LPDG
APIForce Zurich 5 April Automation LPDG
MarianaLemus7
Pigging Solutions Piggable Sweeping Elbows
Pigging Solutions Piggable Sweeping Elbows
Pigging Solutions
Understanding the Laravel MVC Architecture
Understanding the Laravel MVC Architecture
Pixlogix Infotech
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
carlostorres15106
Artificial intelligence in the post-deep learning era
Artificial intelligence in the post-deep learning era
Deakin University
Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?
Mattias Andersson
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)
Wonjun Hwang
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
shyamraj55
costume and set research powerpoint presentation
costume and set research powerpoint presentation
phoebematthew05
SIEMENS: RAPUNZEL – A Tale About Knowledge Graph
SIEMENS: RAPUNZEL – A Tale About Knowledge Graph
Neo4j
Scanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL Certs
Rizwan Syed
Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024
Scott Keck-Warren
Vulnerability_Management_GRC_by Sohang Sengupta.pptx
Vulnerability_Management_GRC_by Sohang Sengupta.pptx
null - The Open Security Community
Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024
Enterprise Knowledge
Making_way_through_DLL_hollowing_inspite_of_CFG_by_Debjeet Banerjee.pptx
Making_way_through_DLL_hollowing_inspite_of_CFG_by_Debjeet Banerjee.pptx
null - The Open Security Community
Hot Sexy call girls in Panjabi Bagh 🔝 9953056974 🔝 Delhi escort Service
Hot Sexy call girls in Panjabi Bagh 🔝 9953056974 🔝 Delhi escort Service
9953056974 Low Rate Call Girls In Saket, Delhi NCR
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
BookNet Canada
Recently uploaded
(20)
Build your next Gen AI Breakthrough - April 2024
Build your next Gen AI Breakthrough - April 2024
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
The transition to renewables in India.pdf
The transition to renewables in India.pdf
APIForce Zurich 5 April Automation LPDG
APIForce Zurich 5 April Automation LPDG
Pigging Solutions Piggable Sweeping Elbows
Pigging Solutions Piggable Sweeping Elbows
Understanding the Laravel MVC Architecture
Understanding the Laravel MVC Architecture
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Artificial intelligence in the post-deep learning era
Artificial intelligence in the post-deep learning era
Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
costume and set research powerpoint presentation
costume and set research powerpoint presentation
SIEMENS: RAPUNZEL – A Tale About Knowledge Graph
SIEMENS: RAPUNZEL – A Tale About Knowledge Graph
Scanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL Certs
Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024
Vulnerability_Management_GRC_by Sohang Sengupta.pptx
Vulnerability_Management_GRC_by Sohang Sengupta.pptx
Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024
Making_way_through_DLL_hollowing_inspite_of_CFG_by_Debjeet Banerjee.pptx
Making_way_through_DLL_hollowing_inspite_of_CFG_by_Debjeet Banerjee.pptx
Hot Sexy call girls in Panjabi Bagh 🔝 9953056974 🔝 Delhi escort Service
Hot Sexy call girls in Panjabi Bagh 🔝 9953056974 🔝 Delhi escort Service
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
C# Tutorial MSM_Murach chapter-09-slides
1.
Murach’s C# 2010, C9
© 2010, Mike Murach & Associates, Inc.Slide 1 Chapter 9 How to work with dates and strings
2.
Murach’s C# 2010, C9
© 2010, Mike Murach & Associates, Inc.Slide 2 Objectives Applied 1. Given the date-handling requirements of an application, write the code that satisfies the requirements. 2. Given the string-handling requirements of an application, write the code that satisfies the requirements. 3. Given the formatting requirements of an application, use the Format method of the String class to provide the formatting. Knowledge 1. Describe the way a DateTime variable is stored. 2. Explain how a String object differs from a StringBuilder object.
3.
Murach’s C# 2010, C9
© 2010, Mike Murach & Associates, Inc.Slide 3 The syntax for creating a DateTime value DateTime variableName = new DateTime(year, month, day [, hour, minute, second[, millisecond]]); Another way to create a DateTime value DateTime variableName = DateTime.Parse(string); Statements that create DateTime values DateTime startDate = new DateTime(10, 01, 30); // 1/30/2010 12:00 AM DateTime startDateAndTime = new DateTime(2010, 1, 30, 14, 15, 0); // 1/30/2010 2:15 PM DateTime startDate = DateTime.Parse("01/30/10"); // 1/30/2010 12:00 AM DateTime startDateAndTime = DateTime.Parse("Jan 30, 2010 2:15 PM"); // 1/30/2010 2:15 PM DateTime invoiceDate = DateTime.Parse(txtInvoiceDate.Text);
4.
Murach’s C# 2010, C9
© 2010, Mike Murach & Associates, Inc.Slide 4 Valid date formats 01/30/2010 1/30/10 01-01-2010 1-1-10 2010-01-01 Jan 30 2010 January 30, 2010 Valid time formats 2:15 PM 14:15 02:15:30 AM
5.
Murach’s C# 2010, C9
© 2010, Mike Murach & Associates, Inc.Slide 5 DateTime properties for getting the current date and time Property Description Now Returns the current date and time. Today Returns the current date. Statements that get the current date and time DateTime currentDateTime = DateTime.Now; // 1/30/2010 4:24:59 AM DateTime currentDate = DateTime.Today; // 1/30/2010 12:00:00 AM
6.
Murach’s C# 2010, C9
© 2010, Mike Murach & Associates, Inc.Slide 6 DateTime methods for formatting a date or time Method Description ToLongDateString() Converts the DateTime value to a string that includes the day of the week name, the month name, the day of the month, and the year. ToShortDateString() Converts the DateTime value to a string that includes the numeric month, day, and year. ToLongTimeString() Converts the DateTime value to a string that includes the hours, minutes, and seconds. ToShortTimeString() Converts the DateTime value to a string that includes the hours and minutes.
7.
Murach’s C# 2010, C9
© 2010, Mike Murach & Associates, Inc.Slide 7 Statements that format dates and times string longDate = currentDateTime.ToLongDateString(); // Wednesday, January 30, 2010 string shortDate = currentDateTime.ToShortDateString(); // 1/30/2010 string longTime = currentDateTime.ToLongTimeString(); // 4:24:59 AM string ShortTime = currentDateTime.ToShortTimeString(); // 4:24 AM Description • The format that’s used for a date or time depends on your computer’s regional settings.
8.
Murach’s C# 2010, C9
© 2010, Mike Murach & Associates, Inc.Slide 8 DateTime properties for working with dates and times Property Description Date Returns the DateTime value with the time portion set to 12:00:00 AM. Month Returns an integer for the month portion of the DateTime value. Day Returns an integer for the day portion of the DateTime value. Year Returns an integer for the year portion of the DateTime value. Hour Returns an integer for the hour portion of the DateTime value. Minute Returns an integer for the minute portion of the DateTime value.
9.
Murach’s C# 2010, C9
© 2010, Mike Murach & Associates, Inc.Slide 9 DateTime properties for working with dates and times (continued) Property Description Second Returns an integer for the second portion of the DateTime value. TimeOfDay Returns a TimeSpan value that represents the amount of time that has elapsed since 12:00:00 AM. DayOfWeek Returns a member of the DayOfWeek enumeration that represents the day of the week of a DateTime value. DayOfYear Returns an integer for the numeric day of the year.
10.
Murach’s C# 2010, C9
© 2010, Mike Murach & Associates, Inc.Slide 10 DateTime methods for working with dates and times (continued) Method Description DaysInMonth(year, month) Returns the number of days in a specified month and year. IsLeapYear(year) Returns a Boolean value that indicates whether or not a specified year is a leap year.
11.
Murach’s C# 2010, C9
© 2010, Mike Murach & Associates, Inc.Slide 11 Statements that get information about a date or time DateTime currentDateTime = DateTime.Now; // 1/30/2010 10:26:35 AM int month = currentDateTime.Month; // 1 int hour = currentDateTime.Hour; // 10 int dayOfYear = currentDateTime.DayOfYear; // 30 int daysInMonth = DateTime.DaysInMonth(2010, 2); // 28 bool isLeapYear = DateTime.IsLeapYear(2010); // false
12.
Murach’s C# 2010, C9
© 2010, Mike Murach & Associates, Inc.Slide 12 Code that uses the DayOfWeek property and enumeration DayOfWeek dayOfWeek = currentDateTime.DayOfWeek; string message = ""; if (dayOfWeek == DayOfWeek.Saturday || dayOfWeek == DayOfWeek.Sunday) { message = "Weekend"; } else { message = "Weekday"; }
13.
Murach’s C# 2010, C9
© 2010, Mike Murach & Associates, Inc.Slide 13 DateTime methods for performing operations on dates and times Method Description AddDays(days) Adds the specified numbers of days to a DateTime value and returns another DateTime value. AddMonths(months) Adds the specified number of months to a DateTime value and returns another DateTime value. AddYears(years) Adds the specified number of years to a DateTime value and returns another DateTime value. AddHours(hours) Adds the specified number of hours to a DateTime value and returns another DateTime value.
14.
Murach’s C# 2010, C9
© 2010, Mike Murach & Associates, Inc.Slide 14 DateTime methods for performing operations on dates and times (continued) Method Description AddMinutes(minutes) Adds the specified number of minutes to a DateTime value and returns another DateTime value. AddSeconds(seconds) Adds the specified number of seconds to a DateTime value and returns another DateTime value. Add(timespan) Adds the specified TimeSpan value to a DateTime value and returns another DateTime value. Subtract(datetime) Subtracts the specified DateTime value from a DateTime value and returns a TimeSpan value.
15.
Murach’s C# 2010, C9
© 2010, Mike Murach & Associates, Inc.Slide 15 Statements that perform operations on dates and times DateTime dateTime = DateTime.Parse("3/1/2010 13:28"); // 3/1/2010 1:28:00 PM DateTime dueDate = dateTime.AddMonths(2); // 5/1/2010 1:28:00 PM dueDate = dateTime.AddDays(60); // 4/30/2010 1:28:00 PM DateTime runTime = dateTime.AddMinutes(30); // 3/1/2010 1:58:00 PM runTime = dateTime.AddHours(12); // 3/2/2010 1:28:00 AM
16.
Murach’s C# 2010, C9
© 2010, Mike Murach & Associates, Inc.Slide 16 Code that results in a TimeSpan value DateTime currentDate = DateTime.Today; // 1/30/2010 dueDate = DateTime.Parse("2/15/2010"); // 2/15/2010 TimeSpan timeTillDue = dueDate.Subtract(currentDate); // 16:00:00:00 int daysTillDue = timeTillDue.Days; // 16 Description • A TimeSpan value represents a period of time stored as ticks. You can use the Days, Hours, Minutes, and Seconds properties of a TimeSpan value to get portions of that value.
17.
Murach’s C# 2010, C9
© 2010, Mike Murach & Associates, Inc.Slide 17 A statement that uses the – operator to subtract two dates TimeSpan timeTillDue = dueDate - currentDate; // 16:00:00:00 An if statement that uses the > operator on DateTime values bool pastDue = false; if (currentDate > dueDate) pastDue = true;
18.
Murach’s C# 2010, C9
© 2010, Mike Murach & Associates, Inc.Slide 18 Common properties and methods of the String class Indexer Description [index] Gets the character at the specified position. Property Description Length Gets the number of characters in the string. Method Description StartsWith(string) Returns a Boolean value that indicates whether or not the string starts with the specified string. EndsWith(string) Returns a Boolean value that indicates whether or not the string ends with the specified string.
19.
Murach’s C# 2010, C9
© 2010, Mike Murach & Associates, Inc.Slide 19 Common properties and methods of the String class (continued) Method Description IndexOf(string[, startIndex]) Returns an integer that represents the position of the first occurrence of the specified string starting at the specified position. LastIndexOf( string[, startIndex]) Returns an integer that represents the position of the last occurrence of the specified string starting at the specified position. Insert(startIndex, string) Returns a string with the specified string inserted beginning at the specified position.
20.
Murach’s C# 2010, C9
© 2010, Mike Murach & Associates, Inc.Slide 20 Common properties and methods of the String class (continued) Method Description PadLeft(totalWidth) Returns a string that’s right-aligned and padded on the left with spaces so it’s the specified width. PadRight(totalWidth) Returns a string that’s left-aligned and padded on the right with spaces so it’s the specified width. Remove(startIndex, count) Returns a string with the specified number of characters removed starting at the specified position. Replace( oldString, newString) Returns a string with all occurrences of the old string replaced with the new string.
21.
Murach’s C# 2010, C9
© 2010, Mike Murach & Associates, Inc.Slide 21 Common properties and methods of the String class (continued) Method Description Substring( startIndex[, length]) Returns the string from the specified position to the end of the string or with the specified length. ToLower() Returns a string in lowercase. ToUpper() Returns a string in uppercase. Trim() Returns a string with leading and trailing spaces removed. Split(splitCharacters) Returns an array of strings where each element is a substring that’s delimited by the specified character or characters.
22.
Murach’s C# 2010, C9
© 2010, Mike Murach & Associates, Inc.Slide 22 Code that uses an index to access a character in a string string chars = "abcdefg"; char a = chars[0]; // 'a' char b = chars[1]; // 'b' Code that uses a for loop to access each character in the chars string string charsAndSpaces = ""; for (int i = 0; i < chars.Length; i++) charsAndSpaces += chars[i] + " "; MessageBox.Show(charsAndSpaces, "String Test");
23.
Murach’s C# 2010, C9
© 2010, Mike Murach & Associates, Inc.Slide 23 Code that uses a foreach loop to access each character in the chars string string charsAndSpaces = ""; foreach (char c in chars) charsAndSpaces += c + " "; MessageBox.Show(charsAndSpaces, "String Test"); Code that uses the StartsWith and EndsWith methods bool startsWithABC = chars.StartsWith("abc"); // true bool endsWithABC = chars.EndsWith("abc"); // false Code that uses the IndexOf method string companyName = "Mike Murach and Associates"; int index1 = companyName.IndexOf(" "); // 4 int index2 = companyName.IndexOf(' '); // 4 int index3 = companyName.IndexOf("Inc."); // -1 int index4 = companyName.LastIndexOf(" "); // 15
24.
Murach’s C# 2010, C9
© 2010, Mike Murach & Associates, Inc.Slide 24 Code that uses the Remove, Insert, and Replace methods companyName = companyName.Remove(0, index1 + 1); companyName = companyName.Insert(companyName.Length, ", Inc."); companyName = companyName.Replace("and", "And"); // Murach And Associates, Inc. Code that uses the Substring, ToUpper, and ToLower methods string firstName = "anne"; string firstLetter = firstName.Substring(0, 1).ToUpper(); string otherLetters = firstName.Substring(1).ToLower(); firstName = firstLetter + otherLetters; // Anne Code that copies one string to another string string s1 = "abc"; string s2 = s1; // this copies the value stored in s1 to s2 s2 = "def"; // this doesn't change the value stored in s1
25.
Murach’s C# 2010, C9
© 2010, Mike Murach & Associates, Inc.Slide 25 Code that parses a first name from a name string string fullName = " Edward C Koop "; // " Edward C Koop " fullName = fullName.Trim(); // "Edward C Koop" int firstSpace = fullName.IndexOf(" "); // 6 string firstName = ""; if (firstSpace == -1) firstName = fullName; else firstName = fullName.Substring(0, firstSpace); // Edward
26.
Murach’s C# 2010, C9
© 2010, Mike Murach & Associates, Inc.Slide 26 Code that parses a string that contains an address string address = " |805 Main Street|Dallas|TX|12345| "; address = address.Trim(); if (address.StartsWith("|")) address = address.Remove(0, 1); if (address.EndsWith("|")) address = address.Remove(address.Length - 1, 1); int cityIndex = address.IndexOf("|") + 1; int stateIndex = address.IndexOf("|", cityIndex) + 1; int zipIndex = address.IndexOf("|", stateIndex) + 1; string street = address.Substring(0, cityIndex - 1); string city = address.Substring( cityIndex, stateIndex - cityIndex - 1); string state = address.Substring( stateIndex, zipIndex - stateIndex - 1); string zipCode = address.Substring(zipIndex);
27.
Murach’s C# 2010, C9
© 2010, Mike Murach & Associates, Inc.Slide 27 Code that uses the Split method to parse the name string string fullName = " Edward C Koop "; fullName = fullName.Trim(); string[] names = fullName.Split(' '); string firstName = names[0]; // Edward Code that uses the Split method to parse the address string address = address.Trim(); if (address.StartsWith("|")) address = address.Remove(0, 1); string[] columns = address.Split('|'); string street = columns[0]; // 805 Main Street string city = columns[1]; // Dallas string state = columns[2]; // TX string zipCode = columns[3]; // 12345
28.
Murach’s C# 2010, C9
© 2010, Mike Murach & Associates, Inc.Slide 28 Code that adds hyphens to a phone number string phoneNumber = "9775551212"; phoneNumber = phoneNumber.Insert(3, "-"); phoneNumber = phoneNumber.Insert(7, "-"); // 977-555-1212 Code that replaces the hyphens in a date with slashes string date = "12-27-2007"; date = date.Replace("-", "/"); // 12/27/2007
29.
Murach’s C# 2010, C9
© 2010, Mike Murach & Associates, Inc.Slide 29 A method that checks if a string contains a decimal value public bool IsDecimal(TextBox textBox, string name) { string s = textBox.Text; int decimalCount = 0; bool validDecimal = true; foreach (char c in s) { if (!( // numeric chars c == '0' || c == '1' || c == '2' || c == '3' || c == '4' || c == '5' || c == '6' || c == '7' || c == '8' || c == '9' || c == '.' || // formatting chars c == '$' || c == '%' || c == ',' || c == ' ' ))
30.
Murach’s C# 2010, C9
© 2010, Mike Murach & Associates, Inc.Slide 30 A method that checks for a decimal value (cont.) { validDecimal = false; break; } if (c == '.') { decimalCount++; } } if (validDecimal && decimalCount <= 1) { return true; } else { MessageBox.Show(name + " must be a decimal value.", "Entry Error"); textBox.Focus(); return false; } }
31.
Murach’s C# 2010, C9
© 2010, Mike Murach & Associates, Inc.Slide 31 A method that strips formatting characters from a numeric string public string Strip(string s) { foreach (char c in s) { if (c == '$' || c == '%' || c == ',' || c == ' ') { int i = s.IndexOf(c); s = s.Remove(i, 1); } } return s; }
32.
Murach’s C# 2010, C9
© 2010, Mike Murach & Associates, Inc.Slide 32 Code that calls the IsDecimal and Strip methods decimal monthlyInvestment = 0; if (IsDecimal(txtMonthlyInvestment, "Monthly Investment") { monthlyInvestment = Convert.ToDecimal( Strip(txtMonthlyInvestment.Text)); }
33.
Murach’s C# 2010, C9
© 2010, Mike Murach & Associates, Inc.Slide 33 The syntax for creating a StringBuilder object StringBuilder variableName = new StringBuilder([value][,][capacity]); Statements that create and initialize StringBuilder objects StringBuilder address1 = new StringBuilder(); // Capacity is 16 StringBuilder address2 = new StringBuilder(10); // Capacity is 10 StringBuilder phoneNumber1 = new StringBuilder("9775551212"); // Capacity is 16 StringBuilder phoneNumber2 = new StringBuilder("9775551212", 10); // Capacity is 10 A statement that simplifies references to the StringBuilder class using System.Text;
34.
Murach’s C# 2010, C9
© 2010, Mike Murach & Associates, Inc.Slide 34 Common properties of the StringBuilder class Indexer Description [index] Gets the character at the specified position. Property Description Length Gets the number of characters in the string. Capacity Gets or sets the number of characters the string can hold.
35.
Murach’s C# 2010, C9
© 2010, Mike Murach & Associates, Inc.Slide 35 Common methods of the StringBuilder class Method Description Append(string) Adds the specified string to the end of the string. Insert(index, string) Inserts the specified string at the specified index in the string. Remove(startIndex, count) Removes the specified number of characters from the string starting at the specified index. Replace(oldString, newString) Replaces all occurrences of the old string with the new string. ToString() Converts the StringBuilder object to a string.
36.
Murach’s C# 2010, C9
© 2010, Mike Murach & Associates, Inc.Slide 36 Code that creates a phone number and inserts dashes StringBuilder phoneNumber = new StringBuilder(10); // Capacity is 10 phoneNumber.Append("9775551212"); // Capacity is 10 phoneNumber.Insert(3, "."); // Capacity is 20 phoneNumber.Insert(7, "."); // 977.555.1212 phoneNumber.Remove(0, 4); // 555.1212 phoneNumber.Replace(".", "-"); // 555-1212 lblPhoneNumber.Text = phoneNumber.ToString(); // 555-1212
37.
Murach’s C# 2010, C9
© 2010, Mike Murach & Associates, Inc.Slide 37 Syntax of the Format method of the String class Format(string, value1[, value2]...) Syntax of a format specification within the string argument {N[, M][:formatString]} Explanation N An integer that indicates the value to be formatted. M An integer that indicates the width of the formatted value. If M is negative, the value will be left-justified. If it’s positive, it will be right- justified. formatString A string of formatting codes. Syntax of a format string positiveformat[;negativeformat[;zeroformat]]
38.
Murach’s C# 2010, C9
© 2010, Mike Murach & Associates, Inc.Slide 38 Standard numeric formatting codes Code Description C or c Formats the number as currency with the specified number of decimal places. D or d Formats an integer with the specified number of digits. E or e Formats the number in scientific (exponential) notation with the specified number of decimal places. F or f Formats the number as a decimal with the specified number of decimal places. G or g Formats the number as a decimal or in scientific notation depending on which is more compact. N or n Formats the number with thousands separators and the specified number of decimal places. P or p Formats the number as a percent with the specified number of decimal places.
39.
Murach’s C# 2010, C9
© 2010, Mike Murach & Associates, Inc.Slide 39 Custom numeric formatting codes Code Description 0 Zero placeholder # Digit placeholder . Decimal point , Thousands separator % Percentage placeholder ; Section separator
40.
Murach’s C# 2010, C9
© 2010, Mike Murach & Associates, Inc.Slide 40 Statements that format a single number string balance1 = String.Format("{0:c}", 1234.56); // $1,234.56 string balance2 = String.Format("{0:$#,##0.00;($#,##0.00)}", -1234.56); // ($1,234.56) string balance3 = String.Format( "{0:$#,##0.00;($#,##0.00);Zero}", 0); // Zero string quantity = String.Format("{0:d3}", 43); // 043 string payment = String.Format("{0:f2}", 432.8175); // 432.82 A statement that formats two numbers string totalDue = String.Format("Invoice total: {0:c}; Amount due: {1:c}.", 354.75, 20); // Invoice total: $354.75; Amount due: $20.00.
41.
Murach’s C# 2010, C9
© 2010, Mike Murach & Associates, Inc.Slide 41 Standard DateTime formatting codes Code Description d Short date D Long date t Short time T Long time f Long date, short time F Long date, long time g Short date, short time G Short date, long time
42.
Murach’s C# 2010, C9
© 2010, Mike Murach & Associates, Inc.Slide 42 Custom DateTime formatting codes Code Description d Day of the month without leading zeros dd Day of the month with leading zeros ddd Abbreviated day name dddd Full day name M Month without leading zeros MM Month with leading zeros MMM Abbreviated month name MMMM Full month name y Two-digit year without leading zero yy Two-digit year with leading zero yyyy Four-digit year / Date separator
43.
Murach’s C# 2010, C9
© 2010, Mike Murach & Associates, Inc.Slide 43 Custom DateTime formatting codes (continued) Code Description h Hour without leading zeros hh Hour with leading zeros H Hour on a 24-hour clock without leading zeros HH Hour on a 24-hour clock with leading zeros m Minutes without leading zeros mm Minutes with leading zeros s Seconds without leading zeros ss Seconds with leading zeros f Fractions of seconds (one f for each decimal place) t First character of AM/PM designator tt Full AM/PM designator : Time separator
44.
Murach’s C# 2010, C9
© 2010, Mike Murach & Associates, Inc.Slide 44 Statements that format dates and times DateTime currentDate = DateTime.Now; // 1/30/2010 10:37:32 PM String.Format("{0:d}", currentDate) // 1/30/2010 String.Format("{0:D}", currentDate) // Saturday, January 30, 2010 String.Format("{0:t}", currentDate) // 10:37 PM String.Format("{0:T}", currentDate) // 10:37:32 PM String.Format("{0:ddd, MMM d, yyyy}", currentDate) // Sat, Jan 30, 2010 String.Format("{0:M/d/yy}", currentDate) // 1/30/10 String.Format("{0:HH:mm:ss}", currentDate) // 22:37:32
Download now