C# Questions & Answers on Operation on Characters for Freshers

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

a) get()
b) Sizeof()
c) lengthof()
d) length()
Answer: d

Explanation: Method length() of string class is used to get the length of the object as string.Length and hence invokes the length() method.
2. 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()
Answer: a

Explanation: getBytes() stores the character in an array of bytes. It uses default character to byte conversions.
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
Answer: c
4. What will be the output of the given code snippet?
  1.  static void main(String args[])
  2.  {
  3.      char chars[] = {'x', 'y', 'z'};
  4.      String s = new String(chars);
  5.      Console.WriteLine(s);
  6.  }
a) x
b) xy
c) z
d) xyz
Answer: d

Explanation: 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
5. Choose the effective stringBuilder method which helps in producing output for the given code?
  1.  static void Main(string[] args)
  2.  {
  3.      StringBuilder s = new StringBuilder("object");
  4.      s./*______*/("Oriented Language");
  5.      Console.WriteLine(s);
  6.      Console.ReadLine();
  7.  }
  8. Output : objectOriented Language
a) Insert()
b) Add()
c) Append()
d) Join()
Answer: c

Explanation: static void Main(string[] args)
{
StringBuilder s = new StringBuilder(“object”);
s.Append(“Oriented Language”);
Console.WriteLine(s);
Console.ReadLine();
}
Output : objectOriented Language
6. What will be the output for the given code snippet?
  1.   static void Main(string[] args)
  2.   {
  3.       string s = " i love you";
  4.       Console.WriteLine(s.IndexOf('l') + "  " + s.lastIndexOf('o') + "  " + s.IndexOf('e'));
  5.       Console.ReadLine();
  6.   }
a) 3 5 7
b) 4 5 6
c) 3 9 6
d) 2 4 6
Answer: c

Explanation: 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
7. Which of these methods of class String is used to extract all the characters from a String object?

a) CHARAT()
b) Remove()
c) charAt()
d) Replace()
Answer: b

Explanation: Replace() replaces all instances of a character with a new character while Remove extracts characters from the string.
8. What will be the output of the given code snippet?
  1.  static void Main(string[] args)
  2.  {
  3.      string c = "hello";
  4.      string  c1 = c.Remove(1);
  5.      Console.WriteLine(c1);
  6.      Console.ReadLine();
  7.  }
a) ello
b) h
c) hell
d) none of the mentioned
Answer: b

Explanation: The remove() deletes characters from the string except the character which is specified with its given position.
Output : h
9. 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
Answer: a
10. How to print \\ on the screen?
a) Console.WriteLine(“\\”);
b) Console.WriteLine(“\\\”);
c) Console.WriteLine(“\\\\”);
d) Console.WriteLine(“\\\\\\”);
Answer: c

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

Related

C# Questions & Answers on Properties and its Applications for Freshers

1. The correct way to implement a read only property add, in a math class is?a) class math { int ad; public int add { get { ...

Linux Questions & Answers on Linux Commands for Freshers– 2

1. Command used to determine the path of an executable file is a) whichb) wherec) wexecd) what Answer: a 2. Command used to count number of character in a file is a) grepb) wcc) countd) cut Ans...

C# Questions & Answers on Introduction of Properties for Freshers

1. Choose the wrong statement about the properties used in C#.NET? a) Each property consists of accessor as get and setb) A property cannot be either read or write onlyc) Properties can be used to ...

Post a Comment

emo-but-icon
:noprob:
:smile:
:shy:
:trope:
:sneered:
:happy:
:escort:
:rapt:
:love:
:heart:
:angry:
:hate:
:sad:
:sigh:
:disappointed:
:cry:
:fear:
:surprise:
:unbelieve:
:shit:
:like:
:dislike:
:clap:
:cuff:
:fist:
:ok:
:file:
:link:
:place:
:contact:

item