SlideShare una empresa de Scribd logo
1 de 2
C# Revisiting the concept of arrays - Strings vs. Char Arrays in C#
Review the following code:
string hello1 = "hello!" ;
char [] hello2 = new char [10]{ 'h' , 'e' , 'l' , 'l' , 'o' , '!' , '0' , '0' , '0' , '0' };
hello1 = "Hi!" ;
hello2[1] = 'h' ;
hello2[2] = 'i' ;
hello2[3] = '!' ;
int len1 = hello1.Length;
int len2 = hello2.Length;
Speak to the ramifications of this code and how strings are handled vs. how arrays of char are
handled - declared, initialized, modified. What does this mean for how you use these particular
language constructs?
Solution
In the code, hello2 will be containing:
{'h','h','i','!','o','!','0','0','0','0'};
Because we are assigning the character values to the individual characters of the array.
hello2[3] ='!';
After this statement, if we put:
hello2[4] ='0';
then hello2 will be:
{'h' 'h', 'i', '!', '0'}
Because '0' marks the end of the string.
C# Revisiting the concept of arrays - Strings vs- Char Arrays in C# Re.docx

Más contenido relacionado

Similar a C# Revisiting the concept of arrays - Strings vs- Char Arrays in C# Re.docx

Similar a C# Revisiting the concept of arrays - Strings vs- Char Arrays in C# Re.docx (8)

Regular Expression
Regular ExpressionRegular Expression
Regular Expression
 
COm1407: Character & Strings
COm1407: Character & StringsCOm1407: Character & Strings
COm1407: Character & Strings
 
String in c
String in cString in c
String in c
 
Cse115 lecture14strings part01
Cse115 lecture14strings part01Cse115 lecture14strings part01
Cse115 lecture14strings part01
 
Strings
StringsStrings
Strings
 
DEFUN 2008 - Real World Haskell
DEFUN 2008 - Real World HaskellDEFUN 2008 - Real World Haskell
DEFUN 2008 - Real World Haskell
 
Introduction to Regular Expressions
Introduction to Regular ExpressionsIntroduction to Regular Expressions
Introduction to Regular Expressions
 
Introduction to regular expressions
Introduction to regular expressionsIntroduction to regular expressions
Introduction to regular expressions
 

Más de marions12

C++ program Revising the Array-Based List ADT Given the data structure.docx
C++ program Revising the Array-Based List ADT Given the data structure.docxC++ program Revising the Array-Based List ADT Given the data structure.docx
C++ program Revising the Array-Based List ADT Given the data structure.docxmarions12
 
C++ help!! Im not familiar with how to save- read file so that the pro.docx
C++ help!! Im not familiar with how to save- read file so that the pro.docxC++ help!! Im not familiar with how to save- read file so that the pro.docx
C++ help!! Im not familiar with how to save- read file so that the pro.docxmarions12
 
c++ computer architecture and memory What is fragmentation- Briefly ex.docx
c++ computer architecture and memory What is fragmentation- Briefly ex.docxc++ computer architecture and memory What is fragmentation- Briefly ex.docx
c++ computer architecture and memory What is fragmentation- Briefly ex.docxmarions12
 
C# There are two schools of thought on the use of implicitly typed var.docx
C# There are two schools of thought on the use of implicitly typed var.docxC# There are two schools of thought on the use of implicitly typed var.docx
C# There are two schools of thought on the use of implicitly typed var.docxmarions12
 
Brief introduction of the WorldComSolutionWorldCom was started by Bill.docx
Brief introduction of the WorldComSolutionWorldCom was started by Bill.docxBrief introduction of the WorldComSolutionWorldCom was started by Bill.docx
Brief introduction of the WorldComSolutionWorldCom was started by Bill.docxmarions12
 
Brief Exercise 5-5 Crane Corporation has the following accounts includ.docx
Brief Exercise 5-5 Crane Corporation has the following accounts includ.docxBrief Exercise 5-5 Crane Corporation has the following accounts includ.docx
Brief Exercise 5-5 Crane Corporation has the following accounts includ.docxmarions12
 
Briefly describe some of the similarities and differences between U-S-.docx
Briefly describe some of the similarities and differences between U-S-.docxBriefly describe some of the similarities and differences between U-S-.docx
Briefly describe some of the similarities and differences between U-S-.docxmarions12
 
Briefly describe what the query evaluation engine performs inside a DB.docx
Briefly describe what the query evaluation engine performs inside a DB.docxBriefly describe what the query evaluation engine performs inside a DB.docx
Briefly describe what the query evaluation engine performs inside a DB.docxmarions12
 
Briefly explain the purposes of adjustments Briefly explain the purp.docx
Briefly explain the purposes of adjustments   Briefly explain the purp.docxBriefly explain the purposes of adjustments   Briefly explain the purp.docx
Briefly explain the purposes of adjustments Briefly explain the purp.docxmarions12
 
Budget Martin Corporation granted a nonqualified stock option to e.docx
Budget    Martin Corporation granted a nonqualified stock option to  e.docxBudget    Martin Corporation granted a nonqualified stock option to  e.docx
Budget Martin Corporation granted a nonqualified stock option to e.docxmarions12
 
Calculate fost of goods sold and ending inventory and analyze effect o (1).docx
Calculate fost of goods sold and ending inventory and analyze effect o (1).docxCalculate fost of goods sold and ending inventory and analyze effect o (1).docx
Calculate fost of goods sold and ending inventory and analyze effect o (1).docxmarions12
 
Calculate fost of goods sold and ending inventory and analyze effect o.docx
Calculate fost of goods sold and ending inventory and analyze effect o.docxCalculate fost of goods sold and ending inventory and analyze effect o.docx
Calculate fost of goods sold and ending inventory and analyze effect o.docxmarions12
 
Ca(OH)2 is insoluble- What is the total concentration of ions if 2M of.docx
Ca(OH)2 is insoluble- What is the total concentration of ions if 2M of.docxCa(OH)2 is insoluble- What is the total concentration of ions if 2M of.docx
Ca(OH)2 is insoluble- What is the total concentration of ions if 2M of.docxmarions12
 
c- Since BEEF hooks to Metasploit- is there any safe way to use the we.docx
c- Since BEEF hooks to Metasploit- is there any safe way to use the we.docxc- Since BEEF hooks to Metasploit- is there any safe way to use the we.docx
c- Since BEEF hooks to Metasploit- is there any safe way to use the we.docxmarions12
 
9- Fill in the following table with names or formulas- as appropriate-.docx
9- Fill in the following table with names or formulas- as appropriate-.docx9- Fill in the following table with names or formulas- as appropriate-.docx
9- Fill in the following table with names or formulas- as appropriate-.docxmarions12
 
9- A combination of sand- salt- and water is an example of a A) homoge.docx
9- A combination of sand- salt- and water is an example of a A) homoge.docx9- A combination of sand- salt- and water is an example of a A) homoge.docx
9- A combination of sand- salt- and water is an example of a A) homoge.docxmarions12
 
8-6- Which of the highlighted elements in Figure P8-6 has the greatest.docx
8-6- Which of the highlighted elements in Figure P8-6 has the greatest.docx8-6- Which of the highlighted elements in Figure P8-6 has the greatest.docx
8-6- Which of the highlighted elements in Figure P8-6 has the greatest.docxmarions12
 
870 The plates of a capacitor are not quite parallel- the distance bet.docx
870 The plates of a capacitor are not quite parallel- the distance bet.docx870 The plates of a capacitor are not quite parallel- the distance bet.docx
870 The plates of a capacitor are not quite parallel- the distance bet.docxmarions12
 
8- What are concurrency design patterns- Explain-Solution8) we have fi.docx
8- What are concurrency design patterns- Explain-Solution8) we have fi.docx8- What are concurrency design patterns- Explain-Solution8) we have fi.docx
8- What are concurrency design patterns- Explain-Solution8) we have fi.docxmarions12
 
8- Calculate the distance from the donor (D) to the acceptor (A) in th.docx
8- Calculate the distance from the donor (D) to the acceptor (A) in th.docx8- Calculate the distance from the donor (D) to the acceptor (A) in th.docx
8- Calculate the distance from the donor (D) to the acceptor (A) in th.docxmarions12
 

Más de marions12 (20)

C++ program Revising the Array-Based List ADT Given the data structure.docx
C++ program Revising the Array-Based List ADT Given the data structure.docxC++ program Revising the Array-Based List ADT Given the data structure.docx
C++ program Revising the Array-Based List ADT Given the data structure.docx
 
C++ help!! Im not familiar with how to save- read file so that the pro.docx
C++ help!! Im not familiar with how to save- read file so that the pro.docxC++ help!! Im not familiar with how to save- read file so that the pro.docx
C++ help!! Im not familiar with how to save- read file so that the pro.docx
 
c++ computer architecture and memory What is fragmentation- Briefly ex.docx
c++ computer architecture and memory What is fragmentation- Briefly ex.docxc++ computer architecture and memory What is fragmentation- Briefly ex.docx
c++ computer architecture and memory What is fragmentation- Briefly ex.docx
 
C# There are two schools of thought on the use of implicitly typed var.docx
C# There are two schools of thought on the use of implicitly typed var.docxC# There are two schools of thought on the use of implicitly typed var.docx
C# There are two schools of thought on the use of implicitly typed var.docx
 
Brief introduction of the WorldComSolutionWorldCom was started by Bill.docx
Brief introduction of the WorldComSolutionWorldCom was started by Bill.docxBrief introduction of the WorldComSolutionWorldCom was started by Bill.docx
Brief introduction of the WorldComSolutionWorldCom was started by Bill.docx
 
Brief Exercise 5-5 Crane Corporation has the following accounts includ.docx
Brief Exercise 5-5 Crane Corporation has the following accounts includ.docxBrief Exercise 5-5 Crane Corporation has the following accounts includ.docx
Brief Exercise 5-5 Crane Corporation has the following accounts includ.docx
 
Briefly describe some of the similarities and differences between U-S-.docx
Briefly describe some of the similarities and differences between U-S-.docxBriefly describe some of the similarities and differences between U-S-.docx
Briefly describe some of the similarities and differences between U-S-.docx
 
Briefly describe what the query evaluation engine performs inside a DB.docx
Briefly describe what the query evaluation engine performs inside a DB.docxBriefly describe what the query evaluation engine performs inside a DB.docx
Briefly describe what the query evaluation engine performs inside a DB.docx
 
Briefly explain the purposes of adjustments Briefly explain the purp.docx
Briefly explain the purposes of adjustments   Briefly explain the purp.docxBriefly explain the purposes of adjustments   Briefly explain the purp.docx
Briefly explain the purposes of adjustments Briefly explain the purp.docx
 
Budget Martin Corporation granted a nonqualified stock option to e.docx
Budget    Martin Corporation granted a nonqualified stock option to  e.docxBudget    Martin Corporation granted a nonqualified stock option to  e.docx
Budget Martin Corporation granted a nonqualified stock option to e.docx
 
Calculate fost of goods sold and ending inventory and analyze effect o (1).docx
Calculate fost of goods sold and ending inventory and analyze effect o (1).docxCalculate fost of goods sold and ending inventory and analyze effect o (1).docx
Calculate fost of goods sold and ending inventory and analyze effect o (1).docx
 
Calculate fost of goods sold and ending inventory and analyze effect o.docx
Calculate fost of goods sold and ending inventory and analyze effect o.docxCalculate fost of goods sold and ending inventory and analyze effect o.docx
Calculate fost of goods sold and ending inventory and analyze effect o.docx
 
Ca(OH)2 is insoluble- What is the total concentration of ions if 2M of.docx
Ca(OH)2 is insoluble- What is the total concentration of ions if 2M of.docxCa(OH)2 is insoluble- What is the total concentration of ions if 2M of.docx
Ca(OH)2 is insoluble- What is the total concentration of ions if 2M of.docx
 
c- Since BEEF hooks to Metasploit- is there any safe way to use the we.docx
c- Since BEEF hooks to Metasploit- is there any safe way to use the we.docxc- Since BEEF hooks to Metasploit- is there any safe way to use the we.docx
c- Since BEEF hooks to Metasploit- is there any safe way to use the we.docx
 
9- Fill in the following table with names or formulas- as appropriate-.docx
9- Fill in the following table with names or formulas- as appropriate-.docx9- Fill in the following table with names or formulas- as appropriate-.docx
9- Fill in the following table with names or formulas- as appropriate-.docx
 
9- A combination of sand- salt- and water is an example of a A) homoge.docx
9- A combination of sand- salt- and water is an example of a A) homoge.docx9- A combination of sand- salt- and water is an example of a A) homoge.docx
9- A combination of sand- salt- and water is an example of a A) homoge.docx
 
8-6- Which of the highlighted elements in Figure P8-6 has the greatest.docx
8-6- Which of the highlighted elements in Figure P8-6 has the greatest.docx8-6- Which of the highlighted elements in Figure P8-6 has the greatest.docx
8-6- Which of the highlighted elements in Figure P8-6 has the greatest.docx
 
870 The plates of a capacitor are not quite parallel- the distance bet.docx
870 The plates of a capacitor are not quite parallel- the distance bet.docx870 The plates of a capacitor are not quite parallel- the distance bet.docx
870 The plates of a capacitor are not quite parallel- the distance bet.docx
 
8- What are concurrency design patterns- Explain-Solution8) we have fi.docx
8- What are concurrency design patterns- Explain-Solution8) we have fi.docx8- What are concurrency design patterns- Explain-Solution8) we have fi.docx
8- What are concurrency design patterns- Explain-Solution8) we have fi.docx
 
8- Calculate the distance from the donor (D) to the acceptor (A) in th.docx
8- Calculate the distance from the donor (D) to the acceptor (A) in th.docx8- Calculate the distance from the donor (D) to the acceptor (A) in th.docx
8- Calculate the distance from the donor (D) to the acceptor (A) in th.docx
 

Último

Keynote by Prof. Wurzer at Nordex about IP-design
Keynote by Prof. Wurzer at Nordex about IP-designKeynote by Prof. Wurzer at Nordex about IP-design
Keynote by Prof. Wurzer at Nordex about IP-designMIPLM
 
INTRODUCTION TO CATHOLIC CHRISTOLOGY.pptx
INTRODUCTION TO CATHOLIC CHRISTOLOGY.pptxINTRODUCTION TO CATHOLIC CHRISTOLOGY.pptx
INTRODUCTION TO CATHOLIC CHRISTOLOGY.pptxHumphrey A Beña
 
ENG 5 Q4 WEEk 1 DAY 1 Restate sentences heard in one’s own words. Use appropr...
ENG 5 Q4 WEEk 1 DAY 1 Restate sentences heard in one’s own words. Use appropr...ENG 5 Q4 WEEk 1 DAY 1 Restate sentences heard in one’s own words. Use appropr...
ENG 5 Q4 WEEk 1 DAY 1 Restate sentences heard in one’s own words. Use appropr...JojoEDelaCruz
 
Influencing policy (training slides from Fast Track Impact)
Influencing policy (training slides from Fast Track Impact)Influencing policy (training slides from Fast Track Impact)
Influencing policy (training slides from Fast Track Impact)Mark Reed
 
Active Learning Strategies (in short ALS).pdf
Active Learning Strategies (in short ALS).pdfActive Learning Strategies (in short ALS).pdf
Active Learning Strategies (in short ALS).pdfPatidar M
 
Full Stack Web Development Course for Beginners
Full Stack Web Development Course  for BeginnersFull Stack Web Development Course  for Beginners
Full Stack Web Development Course for BeginnersSabitha Banu
 
Food processing presentation for bsc agriculture hons
Food processing presentation for bsc agriculture honsFood processing presentation for bsc agriculture hons
Food processing presentation for bsc agriculture honsManeerUddin
 
Choosing the Right CBSE School A Comprehensive Guide for Parents
Choosing the Right CBSE School A Comprehensive Guide for ParentsChoosing the Right CBSE School A Comprehensive Guide for Parents
Choosing the Right CBSE School A Comprehensive Guide for Parentsnavabharathschool99
 
Concurrency Control in Database Management system
Concurrency Control in Database Management systemConcurrency Control in Database Management system
Concurrency Control in Database Management systemChristalin Nelson
 
Q4-PPT-Music9_Lesson-1-Romantic-Opera.pptx
Q4-PPT-Music9_Lesson-1-Romantic-Opera.pptxQ4-PPT-Music9_Lesson-1-Romantic-Opera.pptx
Q4-PPT-Music9_Lesson-1-Romantic-Opera.pptxlancelewisportillo
 
Karra SKD Conference Presentation Revised.pptx
Karra SKD Conference Presentation Revised.pptxKarra SKD Conference Presentation Revised.pptx
Karra SKD Conference Presentation Revised.pptxAshokKarra1
 
Transaction Management in Database Management System
Transaction Management in Database Management SystemTransaction Management in Database Management System
Transaction Management in Database Management SystemChristalin Nelson
 
ROLES IN A STAGE PRODUCTION in arts.pptx
ROLES IN A STAGE PRODUCTION in arts.pptxROLES IN A STAGE PRODUCTION in arts.pptx
ROLES IN A STAGE PRODUCTION in arts.pptxVanesaIglesias10
 
Incoming and Outgoing Shipments in 3 STEPS Using Odoo 17
Incoming and Outgoing Shipments in 3 STEPS Using Odoo 17Incoming and Outgoing Shipments in 3 STEPS Using Odoo 17
Incoming and Outgoing Shipments in 3 STEPS Using Odoo 17Celine George
 
Integumentary System SMP B. Pharm Sem I.ppt
Integumentary System SMP B. Pharm Sem I.pptIntegumentary System SMP B. Pharm Sem I.ppt
Integumentary System SMP B. Pharm Sem I.pptshraddhaparab530
 
Barangay Council for the Protection of Children (BCPC) Orientation.pptx
Barangay Council for the Protection of Children (BCPC) Orientation.pptxBarangay Council for the Protection of Children (BCPC) Orientation.pptx
Barangay Council for the Protection of Children (BCPC) Orientation.pptxCarlos105
 
Music 9 - 4th quarter - Vocal Music of the Romantic Period.pptx
Music 9 - 4th quarter - Vocal Music of the Romantic Period.pptxMusic 9 - 4th quarter - Vocal Music of the Romantic Period.pptx
Music 9 - 4th quarter - Vocal Music of the Romantic Period.pptxleah joy valeriano
 
Daily Lesson Plan in Mathematics Quarter 4
Daily Lesson Plan in Mathematics Quarter 4Daily Lesson Plan in Mathematics Quarter 4
Daily Lesson Plan in Mathematics Quarter 4JOYLYNSAMANIEGO
 

Último (20)

Keynote by Prof. Wurzer at Nordex about IP-design
Keynote by Prof. Wurzer at Nordex about IP-designKeynote by Prof. Wurzer at Nordex about IP-design
Keynote by Prof. Wurzer at Nordex about IP-design
 
INTRODUCTION TO CATHOLIC CHRISTOLOGY.pptx
INTRODUCTION TO CATHOLIC CHRISTOLOGY.pptxINTRODUCTION TO CATHOLIC CHRISTOLOGY.pptx
INTRODUCTION TO CATHOLIC CHRISTOLOGY.pptx
 
ENG 5 Q4 WEEk 1 DAY 1 Restate sentences heard in one’s own words. Use appropr...
ENG 5 Q4 WEEk 1 DAY 1 Restate sentences heard in one’s own words. Use appropr...ENG 5 Q4 WEEk 1 DAY 1 Restate sentences heard in one’s own words. Use appropr...
ENG 5 Q4 WEEk 1 DAY 1 Restate sentences heard in one’s own words. Use appropr...
 
Influencing policy (training slides from Fast Track Impact)
Influencing policy (training slides from Fast Track Impact)Influencing policy (training slides from Fast Track Impact)
Influencing policy (training slides from Fast Track Impact)
 
Active Learning Strategies (in short ALS).pdf
Active Learning Strategies (in short ALS).pdfActive Learning Strategies (in short ALS).pdf
Active Learning Strategies (in short ALS).pdf
 
Full Stack Web Development Course for Beginners
Full Stack Web Development Course  for BeginnersFull Stack Web Development Course  for Beginners
Full Stack Web Development Course for Beginners
 
Food processing presentation for bsc agriculture hons
Food processing presentation for bsc agriculture honsFood processing presentation for bsc agriculture hons
Food processing presentation for bsc agriculture hons
 
YOUVE_GOT_EMAIL_PRELIMS_EL_DORADO_2024.pptx
YOUVE_GOT_EMAIL_PRELIMS_EL_DORADO_2024.pptxYOUVE_GOT_EMAIL_PRELIMS_EL_DORADO_2024.pptx
YOUVE_GOT_EMAIL_PRELIMS_EL_DORADO_2024.pptx
 
Choosing the Right CBSE School A Comprehensive Guide for Parents
Choosing the Right CBSE School A Comprehensive Guide for ParentsChoosing the Right CBSE School A Comprehensive Guide for Parents
Choosing the Right CBSE School A Comprehensive Guide for Parents
 
Concurrency Control in Database Management system
Concurrency Control in Database Management systemConcurrency Control in Database Management system
Concurrency Control in Database Management system
 
Q4-PPT-Music9_Lesson-1-Romantic-Opera.pptx
Q4-PPT-Music9_Lesson-1-Romantic-Opera.pptxQ4-PPT-Music9_Lesson-1-Romantic-Opera.pptx
Q4-PPT-Music9_Lesson-1-Romantic-Opera.pptx
 
Karra SKD Conference Presentation Revised.pptx
Karra SKD Conference Presentation Revised.pptxKarra SKD Conference Presentation Revised.pptx
Karra SKD Conference Presentation Revised.pptx
 
LEFT_ON_C'N_ PRELIMS_EL_DORADO_2024.pptx
LEFT_ON_C'N_ PRELIMS_EL_DORADO_2024.pptxLEFT_ON_C'N_ PRELIMS_EL_DORADO_2024.pptx
LEFT_ON_C'N_ PRELIMS_EL_DORADO_2024.pptx
 
Transaction Management in Database Management System
Transaction Management in Database Management SystemTransaction Management in Database Management System
Transaction Management in Database Management System
 
ROLES IN A STAGE PRODUCTION in arts.pptx
ROLES IN A STAGE PRODUCTION in arts.pptxROLES IN A STAGE PRODUCTION in arts.pptx
ROLES IN A STAGE PRODUCTION in arts.pptx
 
Incoming and Outgoing Shipments in 3 STEPS Using Odoo 17
Incoming and Outgoing Shipments in 3 STEPS Using Odoo 17Incoming and Outgoing Shipments in 3 STEPS Using Odoo 17
Incoming and Outgoing Shipments in 3 STEPS Using Odoo 17
 
Integumentary System SMP B. Pharm Sem I.ppt
Integumentary System SMP B. Pharm Sem I.pptIntegumentary System SMP B. Pharm Sem I.ppt
Integumentary System SMP B. Pharm Sem I.ppt
 
Barangay Council for the Protection of Children (BCPC) Orientation.pptx
Barangay Council for the Protection of Children (BCPC) Orientation.pptxBarangay Council for the Protection of Children (BCPC) Orientation.pptx
Barangay Council for the Protection of Children (BCPC) Orientation.pptx
 
Music 9 - 4th quarter - Vocal Music of the Romantic Period.pptx
Music 9 - 4th quarter - Vocal Music of the Romantic Period.pptxMusic 9 - 4th quarter - Vocal Music of the Romantic Period.pptx
Music 9 - 4th quarter - Vocal Music of the Romantic Period.pptx
 
Daily Lesson Plan in Mathematics Quarter 4
Daily Lesson Plan in Mathematics Quarter 4Daily Lesson Plan in Mathematics Quarter 4
Daily Lesson Plan in Mathematics Quarter 4
 

C# Revisiting the concept of arrays - Strings vs- Char Arrays in C# Re.docx

  • 1. C# Revisiting the concept of arrays - Strings vs. Char Arrays in C# Review the following code: string hello1 = "hello!" ; char [] hello2 = new char [10]{ 'h' , 'e' , 'l' , 'l' , 'o' , '!' , '0' , '0' , '0' , '0' }; hello1 = "Hi!" ; hello2[1] = 'h' ; hello2[2] = 'i' ; hello2[3] = '!' ; int len1 = hello1.Length; int len2 = hello2.Length; Speak to the ramifications of this code and how strings are handled vs. how arrays of char are handled - declared, initialized, modified. What does this mean for how you use these particular language constructs? Solution In the code, hello2 will be containing: {'h','h','i','!','o','!','0','0','0','0'}; Because we are assigning the character values to the individual characters of the array. hello2[3] ='!'; After this statement, if we put: hello2[4] ='0'; then hello2 will be: {'h' 'h', 'i', '!', '0'} Because '0' marks the end of the string.