Users Online

· Guests Online: 51

· Members Online: 0

· Total Members: 188
· Newest Member: meenachowdary055

Forum Threads

Newest Threads
No Threads created
Hottest Threads
No Threads created

Latest Articles

C# Questions & Answers ? Introduction of String Formatting

C# Questions & Answers – Introduction of String Formatting

 

 

 

This section of our 1000+ C# MCQs focuses on basics of string formatting in C# Programming Language.

 

 

 

1. What are strings in C#?
a) a sequence of characters
b) array of characters
c) objects of built-in data type
d) a reference type

Answer: c
Explanation: Generally, a string is defined as a sequence of characters but it is different in C#. In c++, the string is an array of characters. In case of C#, strings are objects of the built-in string data type. Thus, a string is a reference type.

 

 

 

 

2. Select the namespace in which string class is built?
a) System.Text
b) System.Net
c) System.IO
d) None of the mentioned

Answer: a
Explanation: None.

 

 

 

 

3. Select the interfaces defined by the string class?
a) IComparable
b) IComparable<string>
c) ICloneable
d) All of the mentioned

Answer: d
Explanation: None.
 

 

 

 

4. Choose the constructor type used to build strings from character array.
a) public String(value)
b) public String(char[ ] value, int startIndex, int length)
c) public String(char[ ])
d) all of the mentioned

Answer: b
Explanation: public String(char[ ] value) – This form of constructor constructs a string that contains characters in value
public String(char[ ] value, int startIndex, int length) -The second form uses length characters from value, beginning at the index specified by startIndex.

 

 

 

5. Select the operators used for checking the equality in strings:
a) !=
b) >
c) <
d) >=

Answer: a
Explanation: None.
 

 

 

 

6. What does the following C# code set specifies?

  1. public static int Compare(string strA, string strB)

a) Comparison is case and culture sensitive
b) Two strings A and B are compared with each other
c) Output is : >0 for (A > B), <0 for (A < B) else ‘0’ for(A=B)
d) All of the mentioned

Answer: d
Explanation: Compares the string referred to by strA with strB. Returns greater than zero if strA is greater than strB, less than zero if strA is less than strB, and zero if strA and strB are equal. The comparison is case and culture-sensitive.

 

 

 

 

 

7. What will be the output of the following C# code snippet?

  1. static void Main(string[] args)
  2. {
  3.     string s1 = "Hello" + "c" + "Sharp";
  4.     Console.WriteLine(s1);
  5.     Console.ReadLine();
  6. }

a) Hello c Sharp
b) HellocSharp
c) Compile time error
d) Hello

Answer: a
Explanation: Here ‘+’ operator works as concatenation for strings.
Output :

 

Hello c Sharp

 

 

 

 

8. Which of these operators can be used to concatenate two or more String objects?
a) +
b) +=
c) &
d) ||

Answer: a
Explanation: string s1 = “Hello”+ ” I ” + “Love” + ” ComputerScience “;
Console.WriteLine(s1);
Output :

 

Hello I Love ComputerScience.

 

 

 

 

9. What does the following C# code set specify?

  1. public static int Compare(string strA, int indexA, string strB, int indexB, int length, bool ignoreCase)

a) Comparison begins at strA[indexA] and strB[indexB] and runs for length of characters
b) Returns output > 0 for for strA > strB else < 0 for strA < strB else if strA = str B output is 0
c) Comparison is culture sensitive and if ignore case is true, comparison ignores case differences
d) All of the mentioned

Answer: d
Explanation: Compares portions of the strings referred to by strA and strB. The comparison begins at strA[indexA] and strB[indexB] and runs for length characters. Returns greater than zero if strA is greater than strB, less than zero if strA is less than strB, and zero if strA and strB are equal. If ignoreCase is true, the comparison ignores case differences. Otherwise, case differences matter. The comparison is culture-sensitive.

 

 

 

 

10. Which string operation does the below-mentioned method define?

  1. public static string Concat(string str0, string str1)

a) method returns a string
b) string str1 is concatenated to the end of str0
c) can be used to concatenate any number of strings
d) all of the mentioned

Answer: d
Explanation: This method returns a string that contains str1 concatenated to the end of str0. Another form of Concat(), shown here, concatenates three strings:
public static string Concat(string str0, string str1, string str2). Hence, any number of strings can be concatenated using this method.

 

 

 

 

11. Choose the base class for string() method.
a) System.Array
b) System.char
c) System.String
d) None of the mentioned

Answer: c
Explanation: String is an alias for the predefined “System.string” class from which most of the string() methods are derived.

 

 

 

12. Did method use to remove whitespace from the string?
a) Split()
b) Substring()
c) Trim()
d) TrimStart()

Answer: c
Explanation: Perfectly removes whitespace from string whereas TrimStart() removes a string of characters from the end of the string.

 

Comments

No Comments have been Posted.

Post Comment

Please Login to Post a Comment.

Ratings

Rating is available to Members only.

Please login or register to vote.

No Ratings have been Posted.
Render time: 1.14 seconds
10,841,911 unique visits