c 字符串拼接 ##_C#字符串适应性问题和解答 套装2

c 字符串拼接 ##

1) What is the correct output of given code snippets?
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);
}

  1. AXYZBC ABC ABC

  2. ABC ABC ABC

  3. AXYZBC AXYZBC ABC

  4. Syntax Error

Answer & Explanation

Correct answer: 2
ABC ABC ABC

The above code will print "ABC ABC ABC" on console screen.

1)给定代码段的正确输出是什么?
  1. AXYZBC ABC ABC

  2. ABC ABC ABC

  3. AXYZBC AXYZBC ABC

  4. 语法错误

答案与解释

正确答案:2
ABC ABC ABC

上面的代码将在控制台屏幕上打印“ ABC ABC ABC”

2) What is the correct output of given code snippets?
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);
}

  1. AXYZBC ABC ABC

  2. ABC ABC ABC

  3. AXYZBC AXYZBC ABC

  4. Syntax Error

Answer & Explanation

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.

2)给定代码段的正确输出是什么?
  1. AXYZBC ABC ABC

  2. ABC ABC ABC

  3. AXYZBC AXYZBC ABC

  4. 语法错误

答案与解释

正确答案:1
AXYZBC ABC ABC

在上面的源代码中,我们使用了String类的String.Insert()方法。 它将一个字符串插入另一个字符串并返回更新的字符串。

3) If we will access a character from a string that is outside the string size, then which exception will generate?
  1. ArrayIndexOutOfBoundExcepion

  2. IndexOutOfRangeException

  3. OutOfBoundException

  4. StringException

Answer & Explanation

Correct answer: 2
IndexOutOfRangeException

If we access character outside the range of string, it will generate "IndexOutOfRangeException".

3)如果我们将访问超出字符串大小的字符串中的字符,那么将产生哪个异常?
  1. ArrayIndexOutOfBoundExcepion

  2. IndexOutOfRangeException

  3. OutOfBoundException

  4. StringException

答案与解释

正确答案:2
IndexOutOfRangeException

如果我们访问字符串范围之外的字符,它将生成“ IndexOutOfRangeException”

4) What is the correct way to get a character from string in C#.NET?
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");
}

  1. String str="sample"; char ch = str[0];

  2. String str="sample"; char ch = str.getChar(0);

  3. String str="sample"; char ch = str.CharAt(0);

  4. String str="sample"; char ch = str.Char(0);

Answer & Explanation

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.

4)从C#.NET的字符串中获取字符的正确方法是什么?
  1. 字符串str =“ sample”; char ch = str [0];

  2. 字符串str =“ sample”; char ch = str.getChar(0);

  3. 字符串str =“ sample”; char ch = str.CharAt(0);

  4. 字符串str =“ sample”; char ch = str.Char(0);

答案与解释

正确答案:1
字符串str =“ sample”; char ch = str [0];

在上面的代码中,第一个选项是正确的以从字符串中获取字符。

5) What is the correct output of given code snippets?
static void Main(string[] args)
{
	String str = "SAMPLE";

	char ch = str[6];

	Console.WriteLine(ch);
}

  1. E

  2. 'E'

  3. Runtime Exception

  4. Syntax Error

Answer & Explanation

Correct answer: 3
Runtime Exception

The above code will generate runtime exception (IndexOutOfRangeException).

5)给定代码段的正确输出是什么?
  1. Ë

  2. 'E'

  3. 运行时异常

  4. 语法错误

答案与解释

正确答案:3
运行时异常

上面的代码将生成运行时异常( IndexOutOfRangeException )。

翻译自: https://www.includehelp.com/dot-net/csharp-strings-aptitude-questions-and-answers-2.aspx

c 字符串拼接 ##

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值