Revisiting the concept of arrays - Strings vs. Char Arrays Review the following
ID: 3780559 • Letter: R
Question
Revisiting the concept of arrays - Strings vs. Char Arrays
Review the following code:
string hello1 = "hello!";
char[] hello2 = new char[10]{'h','e','l','l','o','!','','','',''};
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?
Explanation / Answer
From the question :
string hello1 = "hello!"; // hllo1 is a string variable which stores hello!
char[] hello2 = new char[10]{'h','e','l','l','o','!','','','',''}; // It is arrays of char hello2 contains hello!
hello1 = "Hi!"; // hello1 data modified with Hi!
hello2[1] ='h'; // hello2[1] contains h
hello2[2] ='i'; // hello2[2] contains i
hello2[3] ='!'; // hello2[3] contains !
int len1 = hello1.Length; // Here length is 3
int len2 = hello2.Length; // Here length is 10
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.