C# Programming Questions and Answers
Select the objects of the class TextWriter which is/are used to perform the write operations to the console?
TextWriter is a class with objects as write() and writeline().
Which of the following statement is correct?
reverse() and replace() are by definition.
Select the method used to write single byte to a file?
To write a byte to a file, the WriteByte( ) method is used. Its simplest form is shown here:
void WriteByte(byte value)
Choose the correct statement about the WriteLine()?
By the definition of writeline().
What would be the output of given code snippet?
staticvoid Main(string[] args)
{
String a ="i love iostream";
Console.WriteLine(a.IndexOf('i')+" "+ a.IndexOf('e')+" "+ a.LastIndexOf('i')+" "+ a.LastIndexOf('e'));
Console.ReadLine();
}
indexof(‘i’) and lastIndexof(‘i’) are pre defined functions which are used to get the index of first and last occurrence of the character pointed by i in the given array.
Output : 0 5 7 12
Select the namespace/namespaces which consists of methods like Length(), Indexer(), Append() for manipulating the strings.
The system.text namespace contains the Stringbuilder class and hence must include using system.text for manipulating the mutable strings.
What will be the output of given code snippet?
staticvoid Main(string[] args)
{
string h ="i lovelife";
string h1 =newstring(h.Reverse().ToArray());
Console.WriteLine(h1);
Console.ReadLine();
}
Reverse() an inbuilt method reverses all the characters singly and hence embed them into the string completely.
Output :efilevol i
What will be the output of given code snippet?
staticvoid Main(string[] args)
{
StringBuilder sb =new StringBuilder("hello world");
sb.Insert(6, "good");
Console.WriteLine(sb);
Console.ReadLine();
}
The insert() method inserts one string into another. It is overloaded to accept values of all simple types, plus String and Objects. String is inserted into invoking object at specified position. “Good ” is inserted in “Hello World” index 6 giving “Hello Good World”.
Which of these classes is used to create an object whose character sequence is mutable?
Mutable strings are dynamic strings. They can grow dynamically as characters are added to them. stringbuilder class supports those methods that are useful for manipulating dynamic strings.