AmbitionBox

Discover Best Places to work in India

C# Programming

C# Programming Questions and Answers

Showing 1 - 8 of 8 questions

1

Which of these methods is an alternative to getChars() that stores the characters in an array of bytes?

a

getBytes()

b

GetByte()

c

giveByte()

d

Give Bytes()

correct answer a

getBytes() stores the character in an array of bytes. It uses default character to byte conversions.

2

What will be the output of the given code snippet?

staticvoid main(String args[])

{

     char chars[]={'x', 'y', 'z'};

     String s =newString(chars);

     Console.WriteLine(s);

}

 

 

a

x

b

xy

c

z

d

xyz

correct answer d

String(chars) is a constructor of class string, it initializes string s with the values stored in character array chars, therefore s contains “xyz”.
Output :xyz

3

Which of these methods can be used to convert all characters in a String into a character array?

a

CharAt()

b

getChars()

c

TocharArray()

d

All of the mentioned

correct answer c

Answer: Option (C)

4

Choose the effective stringBuilder method which helps in producing output for the given code?

staticvoid Main(string[] args)

{

     StringBuilder s =new StringBuilder("object");

     s./*______*/("Oriented Language");

     Console.WriteLine(s);

     Console.ReadLine();

}

Output : objectOriented Language

 

a

Insert()

b

Add()

c

Append()

d

Join()

correct answer c

static void Main(string[] args)
{
StringBuilder s = new StringBuilder(“object”);
s.Append(“Oriented Language”);
Console.WriteLine(s);
Console.ReadLine();
}
Output : objectOriented Language

5

Which of these methods of the class String is used to obtain length of String object?

 

a

get()

b

Sizeof()

c

lengthof()

d

length()

correct answer d

Method length() of string class is used to get the length of the object as string.Length and hence invokes the length() method.

6

How to print \\ on the screen?

a

Console.WriteLine(“\\”);

b

Console.WriteLine(“\\\”);

c

Console.WriteLine(“\\\\”);

d

Console.WriteLine(“\\\\\\”);

correct answer c

Console.WriteLine(“\\\\”);
Output : \\

7

What will be the output for the given code snippet?

staticvoid Main(string[] args)

{

     string s =" i love you";

     Console.WriteLine(s.IndexOf('l')+" "+ s.lastIndexOf('o')+" "+ s.IndexOf('e'));

     Console.ReadLine();

}

 

a

3 5 7

b

4 5 6

c

3 9 6

d

2 4 6

correct answer c

indexof(‘l’) and lastIndexof(‘o’) are pre defined functions which are used to get the index of first and last occurrence of
the character pointed by l and c respectively in the given array.
Output : 3, 9, 6

8

How is a string typically processed?

a

On a character by character basis

b

On a string by string basis

c

Both a & b

d

None of the mentioned

correct answer a

Answer: Option (A)

Select a company to compare with

vs

Similar Companies