c 字符串拼接 ##
1) What is the correct output of given code snippets?
static void Main(string[] args)
{
String str1 = "ABC";
String str2 = "ABC";
if (str1.CompareTo(str2)==0)
Console.WriteLine("Both are equal");
else
Console.WriteLine("Both are not equal");
}
Answer & Explanation
Correct answer: 1
Both are equal
The above code will print "Both are equal" on the console screen.
2) What is the correct output of given code snippets?
static void Main(string[] args)
{
String str = "This is a string";
int i1 = 0;
int i2 = 0;
i1 = str.IndexOf('s');
i2 = str.IndexOf('s', i1 + 1);
Console.WriteLine(i1 + " " + i2);
}
Answer & Explanation
Correct answer: 1
3 6
The above code will print "3 6" on the console screen.
3) A string built using the StringBuilder class is Mutable?
Answer & Explanation
Correct answer: 1
Yes
Yes, It is true.
4) What is the correct output of given code snippets?
static void Main(string[] args)
{
String str1 = "Hello ";
String str2 = "World!";
String str3;
str3 = str1.Concat(str2);
Console.WriteLine(str3);
}
Answer & Explanation
Correct answer: 4
Syntax Error
The above code will generate syntax error, because String class does not have Concat() method.
5) What is the correct output of given code snippets?
static void Main(string[] args)
{
String str1 = "Hello ";
String str2 = "World!";
String str3;
str3 = str1+str2;
Console.WriteLine(str3);
}
Answer & Explanation
Correct answer: 1
Hello World!
In C#.NET, + operator is used to concatenate two strings.
翻译自: https://www.includehelp.com/dot-net/csharp-strings-aptitude-questions-and-answers-4.aspx
c 字符串拼接 ##