AmbitionBox

Discover Best Places to work in India

C# Programming

C# Programming Questions and Answers

Showing 1 - 9 of 9 questions

1

Select the objects of the class TextWriter which is/are used to perform the write operations to the console?

a

Write()

b

WriteLine()

c

WriteError()

d

All of the mentioned

correct answer a,b

TextWriter is a class with objects as write() and writeline().

2

Which of the following statement is correct?

a

reverse() method reverses all characters.

b

reverseall() method reverses all characters.

c

replace() method replaces all instances of a character with new character.

d

replace() method replaces first occurrence of a character in invoking string with another character

correct answer a,c

reverse() and replace() are by definition.

3

Select the method used to write single byte to a file?

a

Write()

b

Wrteline()

c

WriteByte()

d

All of the mentioned

correct answer c

To write a byte to a file, the WriteByte( ) method is used. Its simplest form is shown here:
void WriteByte(byte value)

4

Choose the correct statement about the WriteLine()?

a

Can display one or more value to the screen

b

Adds a newline character at the end of the each new output

c

Allows to output data in as many different formats

d

None of the mentioned

correct answer a,b,c

By the definition of writeline().

5

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();

}

 

 

a

0 6 7 8

b

0 5 7 9

c

5 9 0 7

d

0 5 7 12

correct answer d

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

6

Select the namespace/namespaces which consists of methods like Length(), Indexer(), Append() for manipulating the strings.

a

System.Class

b

System.Array

c

System.Text

d

None of the mentioned

correct answer c

The system.text namespace contains the Stringbuilder class and hence must include using system.text for manipulating the mutable strings.

7

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();

}

 

 

 

a

efil evoli

b

lifelove i

c

efilevol i

d

efil evol i

correct answer c

Reverse() an inbuilt method reverses all the characters singly and hence embed them into the string completely.
Output :efilevol i

8

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();

}

 

 

a

hello 6world

b

hello good world

c

hello goodworld

d

hello good world

correct answer c

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”.

9

Which of these classes is used to create an object whose character sequence is mutable?

a

String()

b

StringBuilder()

c

Both of the mentioned

d

None of the mentioned

correct answer b

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.

Select a company to compare with

vs

Similar Companies