c++ ##_##
Methods are used for the reusability of code.
The ref keyword is used to implement pass by reference.
Methods cannot be declared in the class.
In C #, methods cannot call recursively.
Options:
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.
方法用于代码的可重用性。
ref关键字用于实现按引用传递。
方法不能在类中声明。
在C#中,方法不能递归调用。
选项:
正确答案:3
A和B
通过创建方法,我们可以多次重用相同的功能。 我们已经通过值传递和通过引用传递了两种参数传递机制。
Correct answer: 2
Only 1 value
The maximum 1 value can be returned from methods in C#.
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.
正确答案:2
它不返回任何值
如果我们声明一个返回类型为“ void”的方法,则意味着我们不想返回任何值形式的方法。
Correct answer: 1
Program entry point
The program entry point can only occur one time in C# programs, other options can occur multiple times.
ref
out
default argument
actual argument
Options:
Correct answer: 3
A and B
In C#, ref and out both types of arguments are used to get updated value from a method.
参考
出
默认参数
实际论点
选项:
正确答案:3
A和B
在C#中,使用ref和out这两种类型的参数来从方法中获取更新的值。
Correct answer: 1
Yes
Yes, it is possible to have arguments with default values in methods.
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.
Correct answer: 1
Yes
Yes, it is mandatory that the arguments should initialize before returning to the calling methods.
Correct answer: 1
Yes
The default argument must be placed at the end of the argument list in the method.
Static methods are called by class name.
The static keyword is not required to create a static method.
A non-Static method cannot be called a static method.
Static methods can never be public.
Options:
Correct answer: 4
A and C
Statement A and C are correct about static methods.
静态方法由类名称调用。
创建静态方法不需要static关键字。
非静态方法不能称为静态方法。
静态方法永远不能公开。
选项:
正确答案:4
A和C
语句A和C关于静态方法是正确的。
Static
Public
Protected
Internal
Options:
Correct answer: 1
Only A
In C#, there are following access specifiers are available:
Public
Private
Protected
Internal
Protected internal
静态的
上市
受保护的
内部
选项:
正确答案:1
只有一个
在C#中,可以使用以下访问说明符:
上市
私人的
受保护的
内部
内部保护
Correct answer: 2
No
No, private methods can never be accessed outside the class.
public class Ex
{
public void sayhello()
{
Console.WriteLine("Hello World");
}
static public void Main()
{
sayhello();
}
}
Correct answer: 3
Syntax error
We cannot call a non-static method from a static method.
public class Ex
{
private static void sayhello()
{
Console.WriteLine("Hello World");
}
static public void Main()
{
sayhello();
}
}
Correct answer: 1
Hello World
The above program will print "Hello World" message on the console screen.
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);
}
}
Correct answer: 2
Result : 1
In the method calculateFactorial() loop will execute only once, because for second-time condition get false.
正确答案:2
结果:1
在该方法中, calculateFactorial()循环将只执行一次,因为第二次条件为假。
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);
}
}
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.
正确答案:4
语法错误
上面的代码将产生编译时错误,因为方法calculateFactorial()返回一个浮点值,并且我们将其分配给一个整数值。 这样就不可能进行隐式转换。
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);
}
}
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.
正确答案:3
编译器错误
上面的程序生成一个编译时错误,因为我们无法使用该类的对象访问静态方法。
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);
}
}
Correct answer: 3
Compiler Error
The above program generates a compile-time error because we cannot create any method outside the class.
正确答案:3
编译器错误
上面的程序生成一个编译时错误,因为我们不能在类之外创建任何方法。
Correct answer: 1
Yes
Yes, we can create more than one method with the same name using method overloading.
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('#');
}
}
Correct answer: 2
* #
The above method will print "* #" on the console screen.
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);
}
}
Correct answer: 3
25 125
The above program will print (25 125) on the console screen.
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.
正确答案:3
公共静态整数MyMethod(string s,char c){...}
选项3是根据给定要求创建方法的正确方法。
Correct answer: 2
public static void MyMethod(object X) {...}
The option 2 is the correct way to create method according to given requirement.
正确答案:2
公共静态无效MyMethod(对象X){...}
选项2是根据给定要求创建方法的正确方法。
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);
}
}
Correct answer: 1
Syntax Error
We cannot use the return statement in a method that's return type is void.
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);
}
}
Correct answer: 1
Syntax Error
We cannot return more than one value using the return statement.
翻译自: https://www.includehelp.com/dot-net/csharp-methods-aptitude-questions-and-answers.aspx
c++ ##_##