PdfPrep.com

Which of the following code segments will you choose to accomplish this task?

You work as a Software Developer for ABC Inc. The company uses Visual Studio .NET 2005 as its application development platform. You create an application named StringRW

using .NET Framework. You store some characters into an array of Unicode characters. You need to write all or some of these characters into a String object.

Which of the following code segments will you choose to accomplish this task? Each correct answer represents a complete solution. Choose all that apply.
A . StringBuilder sb = new StringBuilder("This is my character String Builder");
char[] b = { ‘c’, ‘l’, ‘a’, ‘s’, ‘s’, ‘r’, ‘i’, ‘g’, ‘h’, ‘t’, ‘d’, ‘o’, ‘d’ };
StringWriter sw = new StringWriter(sb);
Object obj=(Object)b;
sw.Write(obj);
Console.WriteLine(sb);
sw.Close();
B . StringBuilder sb = new StringBuilder("This is my character String Builder");
char[] b = { ‘c’, ‘l’, ‘a’, ‘s’, ‘s’, ‘r’, ‘i’, ‘g’, ‘h’, ‘t’, ‘d’, ‘o’, ‘d’ };
StringWriter sw = new StringWriter(sb);
sw.Write(b);
Console.WriteLine(sb);
sw.Close();

C . StringBuilder sb = new StringBuilder("This is my character String Builder");
char[] b = { ‘c’, ‘l’, ‘a’, ‘s’, ‘s’, ‘r’, ‘i’, ‘g’, ‘h’, ‘t’, ‘d’, ‘o’, ‘d’ }; string str=new string(b);
StringWriter sw = new StringWriter(sb);
sw.Write(str);
Console.WriteLine(sb);
sw.Close();

D . StringBuilder sb = new StringBuilder("This is my character String Builder");
char[] b = { ‘c’, ‘l’, ‘a’, ‘s’, ‘s’, ‘r’, ‘i’, ‘g’, ‘h’, ‘t’, ‘d’, ‘o’, ‘d’ };
StringWriter sw = new StringWriter(sb);
sw.Write(b, 0, 5);
Console.WriteLine(sb);
sw.Close();

Answer: B,C,D

Exit mobile version