c++ ##_##_C#方法能力问题和答案

c++ ##_##

1) There are following statements are given below, which of them are correct about methods in C#?
  1. Methods are used for the reusability of code.

  2. The ref keyword is used to implement pass by reference.

  3. Methods cannot be declared in the class.

  4. In C #, methods cannot call recursively.

Options:

  1. Only A

  2. Only B

  3. A and B

  4. C and D

Answer & Explanation

Correct answer: 3
A and B

We can reuse the same functionality multiple times by creating methods. We have passed by value and pass by reference both mechanisms for parameter passing.

1)下面给出了以下语句,其中哪些对于C#中的方法是正确的?
  1. 方法用于代码的可重用性。

  2. ref关键字用于实现按引用传递。

  3. 方法不能在类中声明。

  4. 在C#中,方法不能递归调用。

选项:

  1. 只有一个

  2. 只有B

  3. A和B

  4. C和D

答案与解释

正确答案:3
A和B

通过创建方法,我们可以多次重用相同的功能。 我们已经通过值传递和通过引用传递了两种参数传递机制。

2) How many values a method can return in C#?
  1. Any number of values

  2. Only 1 value

  3. Depends on the argument passed

  4. Depends on class

Answer & Explanation

Correct answer: 2
Only 1 value

The maximum 1 value can be returned from methods in C#.

2)一个方法可以在C#中返回多少个值?
  1. 任意数量的值

  2. 只有1个值

  3. 取决于传递的参数

  4. 取决于阶级

答案与解释

正确答案:2
只有1个值

可以从C#中的方法返回最大值1。

3) If the return type of method is "void" then what is returns?
  1. It returns void type values

  2. It does not return any value

  3. "void" is not the valid return type

  4. It returns three string values

Answer & Explanation

Correct answer: 2
It does not return any value

If we declare a method with return type "void", it means we do not want to return any value form method.

3)如果方法的返回类型为“ void”,那么返回什么?
  1. 它返回空类型值

  2. 它不返回任何值

  3. “ void”不是有效的返回类型

  4. 它返回三个字符串值

答案与解释

正确答案:2
它不返回任何值

如果我们声明一个返回类型为“ void”的方法,则意味着我们不想返回任何值形式的方法。

4) There are following options are given below, which of them CANNOT occur more than one time in a C# program?
  1. Program entry point

  2. Namespace

  3. Class

  4. Methods

Answer & Explanation

Correct answer: 1
Program entry point

The program entry point can only occur one time in C# programs, other options can occur multiple times.

4)下面给出了以下选项,其中哪些不能在C#程序中多次出现?
  1. 程序入口点

  2. 命名空间

  3. 方法

答案与解释

正确答案:1
程序入口点

程序入口点只能在C#程序中出现一次,其他选项可以多次出现。

5) What kind of arguments we used to get updated value from methods?
  1. ref

  2. out

  3. default argument

  4. actual argument

Options:

  1. Only C

  2. Only D

  3. A and B

  4. Only A

Answer & Explanation

Correct answer: 3
A and B

In C#, ref and out both types of arguments are used to get updated value from a method.

5)我们用来从方法中获取更新值的参数是什么?
  1. 参考

  2. 默认参数

  3. 实际论点

选项:

  1. 只有C

  2. 只有D

  3. A和B

  4. 只有一个

答案与解释

正确答案:3
A和B

在C#中,使用refout这两种类型的参数来从方法中获取更新的值。

6) Is it possible to have arguments with default values in C# methods?
  1. Yes

  2. No

Answer & Explanation

Correct answer: 1
Yes

Yes, it is possible to have arguments with default values in methods.

6)在C#方法中是否可以使用具有默认值的参数?
  1. 没有

答案与解释

正确答案:1

是的 ,方法中可以包含具有默认值的参数。

7) Is it required the arguments should NOT initialize before it pass to ref in the method?
  1. Yes

  2. No

Answer & Explanation

Correct answer: 2
No

When we use ref keyword to pass arguments to the method, it is mandatory to initialize before it passes to the method.

7)是否要求参数在传递给方法中的ref之前不应该初始化?
  1. 没有

答案与解释

正确答案:2
没有

当我们使用ref关键字将参数传递给方法时,必须在将其传递给方法之前进行初始化。

8) In the case of "out" parameters, is it required the arguments should initialize before returning to the calling methods?
  1. Yes

  2. No

Answer & Explanation

Correct answer: 1
Yes

Yes, it is mandatory that the arguments should initialize before returning to the calling methods.

8)对于“ out”参数,是否需要在返回调用方法之前对参数进行初始化?
  1. 没有

答案与解释

正确答案:1

是的 ,在返回调用方法之前,必须对参数进行初始化。

9) The optional or default argument must be placed at the end of the argument list in the method.
  1. Yes

  2. No

Answer & Explanation

Correct answer: 1
Yes

The default argument must be placed at the end of the argument list in the method.

9)可选或默认参数必须放在方法中参数列表的末尾。
  1. 没有

答案与解释

正确答案:1

默认参数必须放在方法中参数列表的末尾。

10) There are following statements are given below, which of them are correct about the static method?
  1. Static methods are called by class name.

  2. The static keyword is not required to create a static method.

  3. A non-Static method cannot be called a static method.

  4. Static methods can never be public.

Options:

  1. Only A

  2. Only C

  3. Only D

  4. A and C

Answer & Explanation

Correct answer: 4
A and C

Statement A and C are correct about static methods.

10)下面给出了以下语句,其中哪些对于静态方法是正确的?
  1. 静态方法由类名称调用。

  2. 创建静态方法不需要static关键字。

  3. 非静态方法不能称为静态方法。

  4. 静态方法永远不能公开。

选项:

  1. 只有一个

  2. 只有C

  3. 只有D

  4. A和C

答案与解释

正确答案:4
A和C

语句A和C关于静态方法是正确的。

11) There are the following keywords that are given below, which of them are NOT access specifiers in C#?
  1. Static

  2. Public

  3. Protected

  4. Internal

Options:

  1. Only A

  2. Only D

  3. A and D

  4. B and C

Answer & Explanation

Correct answer: 1
Only A

In C#, there are following access specifiers are available:

  • Public

  • Private

  • Protected

  • Internal

  • Protected internal

11)下面给出了以下关键字,其中哪些不是C#中的访问说明符?
  1. 静态的

  2. 上市

  3. 受保护的

  4. 内部

选项:

  1. 只有一个

  2. 只有D

  3. A和D

  4. B和C

答案与解释

正确答案:1
只有一个

在C#中,可以使用以下访问说明符:

  • 上市

  • 私人的

  • 受保护的

  • 内部

  • 内部保护

12) Can be access to private methods outside the class?
  1. Yes

  2. No

Answer & Explanation

Correct answer: 2
No

No, private methods can never be accessed outside the class.

12)可以在类之外访问私有方法吗?
  1. 没有

答案与解释

正确答案:2
没有

,私有方法永远不能在类外部访问。

13) What is the correct output of given code snippets?
public class Ex
{
    public void sayhello()
    {

        Console.WriteLine("Hello World");
    }
    static public void Main()
    {
        sayhello();
    }
}

  1. Hello World

  2. Runtime Exception

  3. Syntax error

  4. Array index out of bound

Answer & Explanation

Correct answer: 3
Syntax error

We cannot call a non-static method from a static method.

13)给定代码段的正确输出是什么?
  1. 你好,世界

  2. 运行时异常

  3. 语法错误

  4. 数组索引超出范围

答案与解释

正确答案:3
语法错误

我们不能从静态方法中调用非静态方法。

14) What is the correct output of given code snippets?
public class Ex
{
    private static void sayhello()
    {
        Console.WriteLine("Hello World");
    }
    static public void Main()
    {
        sayhello();
    }
}

  1. Hello World

  2. Runtime Exception

  3. Syntax error

  4. Array index out of bound

Answer & Explanation

Correct answer: 1
Hello World

The above program will print "Hello World" message on the console screen.

14)给定代码段的正确输出是什么?
  1. 你好,世界

  2. 运行时异常

  3. 语法错误

  4. 数组索引超出范围

答案与解释

正确答案:1
你好,世界

上面的程序将在控制台屏幕上打印“ Hello World”消息。

15) What is the correct output of given code snippets?
public class Ex
{
    public static int calculateFactorial(int num)
    {
        int i       = 0;
        int fact    = 1;

        for (i = 1; i >= num; i++)
        {
            fact = fact * i;        
        }

        return fact;
    }
    static public void Main()
    {
        int num     = 5;
        int result  = 0;

        result = calculateFactorial(num);

        Console.WriteLine("Result : "+result);
    }
}

  1. Result : 120

  2. Result : 1

  3. Runtime Exception

  4. Syntax error

Answer & Explanation

Correct answer: 2
Result : 1

In the method calculateFactorial() loop will execute only once, because for second-time condition get false.

15)给定代码段的正确输出是什么?
  1. 结果:120

  2. 结果:1

  3. 运行时异常

  4. 语法错误

答案与解释

正确答案:2
结果:1

在该方法中, calculateFactorial()循环将只执行一次,因为第二次条件为假。

16) What is the correct output of given code snippets?
using System;

public class Ex
{
    public static float calculateFactorial(int num)
    {
        int i       = 0;
        float fact    = 1;

        for (i = 1; i <= num; i++)
        {
            fact = fact * i;        
        }

        return fact;
    }
    static public void Main()
    {
        int num     = 5;
        int result  = 0;

        result = calculateFactorial(num);

        Console.WriteLine("Result : "+result);
    }
}

  1. Result : 120

  2. Result : 1

  3. Runtime Exception

  4. Syntax error

Answer & Explanation

Correct answer: 4
Syntax error

The above code will generate compile-time error, because method calculateFactorial() returns a float value and we are assigning it to an integer value. Then this implicit conversion is not possible.

16)给定代码段的正确输出是什么?
  1. 结果:120

  2. 结果:1

  3. 运行时异常

  4. 语法错误

答案与解释

正确答案:4
语法错误

上面的代码将产生编译时错误,因为方法calculateFactorial()返回一个浮点值,并且我们将其分配给一个整数值。 这样就不可能进行隐式转换。

17) What is the correct output of given code snippets?
using System;

public class Sample
{
    public static void printTable(int num)
    {
        int i       = 0;
        
        for (i = 1; i <= 10; i++)
        {
            Console.Write(num * i + " ");        
        }
    }
    static public void Main()
    {
        Sample S = new Sample();
        S.printTable(3);
    }
}

  1. 2 4 6 8 10 12 14 16 18 20

  2. 2 4 6 8 10 12 14 16 18

  3. Compiler Error

  4. Runtime Exception

Answer & Explanation

Correct answer: 3
Compiler Error

The above program generates a compile-time error, because we cannot access a static method using the object of the class.

17)给定代码段的正确输出是什么?
  1. 2 4 6 8 10 12 14 16 18 20

  2. 2 4 6 8 10 12 14 16 18

  3. 编译器错误

  4. 运行时异常

答案与解释

正确答案:3
编译器错误

上面的程序生成一个编译时错误,因为我们无法使用该类的对象访问静态方法。

18) What is the correct output of given code snippets?
using System;

public static void printTable(int num)
{
    int i       = 0;
        
    for (i = 1; i <= 10; i++)
    {
        Console.Write(num * i + " ");        
    }
}
public class Sample
{
    
    static public void Main()
    {
        printTable(3);
    }
}

  1. 2 4 6 8 10 12 14 16 18 20

  2. 2 4 6 8 10 12 14 16 18

  3. Compiler Error

  4. Runtime Exception

Answer & Explanation

Correct answer: 3
Compiler Error

The above program generates a compile-time error because we cannot create any method outside the class.

18)给定代码段的正确输出是什么?
  1. 2 4 6 8 10 12 14 16 18 20

  2. 2 4 6 8 10 12 14 16 18

  3. 编译器错误

  4. 运行时异常

答案与解释

正确答案:3
编译器错误

上面的程序生成一个编译时错误,因为我们不能在类之外创建任何方法。

19) In C# can we create more than one method with the same name?
  1. Yes

  2. No

Answer & Explanation

Correct answer: 1
Yes

Yes, we can create more than one method with the same name using method overloading.

19)在C#中,我们可以创建多个同名方法吗?
  1. 没有

答案与解释

正确答案:1

是的 ,我们可以使用方法重载创建多个同名方法。

20) What is the correct output of given code snippets?
using System;

public class Sample
{
    static public void printChar()
    {
        Console.Write("* ");
    }
    static public int printChar(char ch)
    {
        Console.Write(ch+" ");
        return 1;
    }
    static public void Main()
    {
        printChar();
        printChar('#');
    }
}

  1. Syntax Error

  2. * #

  3. Runtime Error

  4. # *

Answer & Explanation

Correct answer: 2
* #

The above method will print "* #" on the console screen.

20)给定代码段的正确输出是什么?
  1. 语法错误

  2. *#

  3. 运行时错误

  4. #*

答案与解释

正确答案:2
*#

以上方法将在控制台屏幕上打印“ *#”

21) What is the correct output of given code snippets?
using System;

public class Sample
{
    public static void MyMethod(int A, ref int X, ref int Y)
    {
        X = A * A;
        Y = A * A * A;
    }

    static public void Main()
    {

        int AA = 5;
        int xx = 0;
        int yy = 0;

        MyMethod(AA, ref xx, ref yy);
        Console.WriteLine("Values: {0},{1}", xx, yy);
    }
}

  1. 25 25

  2. 0 0

  3. 25 125

  4. 125 25

Answer & Explanation

Correct answer: 3
25 125

The above program will print (25 125) on the console screen.

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

  2. 0 0

  3. 25125

  4. 125 25

答案与解释

正确答案:3
25125

以上程序将在控制台屏幕上打印(25 125)。

22) If we want to create a static method MyMethod() is to receive a string and a char and it returns a int then what is the correct way to define this method?
  1. public int static MyMethod(string s, char c) {...}

  2. public int MyMethod(string s, char c) {...}

  3. public static int MyMethod(string s, char c) {...}

  4. public static MyMethod(string s, char c) {...}

Answer & Explanation

Correct answer: 3
public static int MyMethod(string s, char c) {...}

Option 3 is the correct way to create a method according to a given requirement.

22)如果我们要创建一个静态方法MyMethod()来接收一个字符串和一个char并返回一个int值,那么定义此方法的正确方法是什么?
  1. public int静态MyMethod(string s,char c){...}

  2. public int MyMethod(string s,char c){...}

  3. 公共静态整数MyMethod(string s,char c){...}

  4. 公共静态MyMethod(string s,char c){...}

答案与解释

正确答案:3
公共静态整数MyMethod(string s,char c){...}

选项3是根据给定要求创建方法的正确方法。

23) If we want to create a static method MyMethod() that accept int or sometime string then what is the correct way to define this method?
  1. public static void MyMethod(int X) {...}

  2. public static void MyMethod(object X) {...}

  3. public static void MyMethod(string X) {...}

  4. public static void MyMethod(int X, string Y) {...}

Answer & Explanation

Correct answer: 2
public static void MyMethod(object X) {...}

The option 2 is the correct way to create method according to given requirement.

23)如果我们要创建一个接受int或某个时间字符串的静态方法MyMethod(),那么定义此方法的正确方法是什么?
  1. 公共静态无效MyMethod(int X){...}

  2. 公共静态无效MyMethod(对象X){...}

  3. 公共静态无效MyMethod(字符串X){...}

  4. 公共静态无效MyMethod(int X,字符串Y){...}

答案与解释

正确答案:2
公共静态无效MyMethod(对象X){...}

选项2是根据给定要求创建方法的正确方法。

24) What is the correct output of given code snippets?
using System;

public class Sample
{
    public static void MyMethod(int A, ref int X, ref int Y)
    {
        X = A * A;
        Y = A * A * A;

        return 0;
    }

    static public void Main()
    {

        int AA = 5;
        int xx = 0;
        int yy = 0;

        MyMethod(AA, ref xx, ref yy);
        Console.WriteLine("Values: {0},{1}", xx, yy);
    }
}

  1. Syntax Error

  2. 25 125

  3. Runtime Exception

  4. 125 125

Answer & Explanation

Correct answer: 1
Syntax Error

We cannot use the return statement in a method that's return type is void.

24)给定代码段的正确输出是什么?
  1. 语法错误

  2. 25125

  3. 运行时异常

  4. 125125

答案与解释

正确答案:1
语法错误

我们不能在返回类型为void的方法中使用return语句。

25) What is the correct output of given code snippets?
using System;

public class Sample
{
    public static int MyMethod(int A, ref int X, ref int Y)
    {
        X = A * A;
        Y = A * A * A;

        return X,Y;
    }

    static public void Main()
    {

        int AA = 5;
        int xx = 0;
        int yy = 0;

        MyMethod(AA, ref xx, ref yy);
        Console.WriteLine("Values: {0},{1}", xx, yy);
    }
}

  1. Syntax Error

  2. 25 125

  3. Runtime Exception

  4. 125 125

Answer & Explanation

Correct answer: 1
Syntax Error

We cannot return more than one value using the return statement.

25)给定代码段的正确输出是什么?
  1. 语法错误

  2. 25125

  3. 运行时异常

  4. 125125

答案与解释

正确答案:1
语法错误

我们不能使用return语句返回多个值。

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

c++ ##_##

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

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值