c 字符串拼接 ##
static void Main(string[] args)
{
String STR1 = "ABC";
String STR2;
String STR3;
STR2 = STR1;
STR3 = String.Copy(STR1);
STR1.Insert(1, "XYZ");
Console.WriteLine(STR1 + " " + STR2 + " "+STR3);
}
Correct answer: 2
ABC ABC ABC
The above code will print "ABC ABC ABC" on console screen.
正确答案:2
ABC ABC ABC
上面的代码将在控制台屏幕上打印“ ABC ABC ABC” 。
static void Main(string[] args)
{
String STR1 = "ABC";
String STR2;
String STR3;
STR2 = STR1;
STR3 = String.Copy(STR1);
STR1 = STR1.Insert(1, "XYZ");
Console.WriteLine(STR1 + " " + STR2 + " "+STR3);
}
Correct answer: 1
AXYZBC ABC ABC
In the above source code, we have used String.Insert() method of String class. It inserts a string into another string and returns the updated string.
正确答案:1
AXYZBC ABC ABC
在上面的源代码中,我们使用了String类的String.Insert()方法。 它将一个字符串插入另一个字符串并返回更新的字符串。
Correct answer: 2
IndexOutOfRangeException
If we access character outside the range of string, it will generate "IndexOutOfRangeException".
正确答案:2
IndexOutOfRangeException
如果我们访问字符串范围之外的字符,它将生成“ IndexOutOfRangeException” 。
static void Main(string[] args)
{
String s1 = "ABC";
string s2 = "ABC";
if(s1==s2)
Console.WriteLine("S1 and S2 are equal");
else
Console.WriteLine("S1 and S2 are not equal");
}
Correct answer: 1
String str="sample"; char ch = str[0];
In the above code, the first option is correct to get a character from string.
正确答案:1
字符串str =“ sample”; char ch = str [0];
在上面的代码中,第一个选项是正确的以从字符串中获取字符。
static void Main(string[] args)
{
String str = "SAMPLE";
char ch = str[6];
Console.WriteLine(ch);
}
Correct answer: 3
Runtime Exception
The above code will generate runtime exception (IndexOutOfRangeException).
翻译自: https://www.includehelp.com/dot-net/csharp-strings-aptitude-questions-and-answers-2.aspx
c 字符串拼接 ##