c# 构造函数 析构函数
Constructors are not required in a class.
Constructors are used to initializing data members of the class.
The constructor name and class name must be the same.
Contractors are old technique, now a day they are deprecated.
Options:
Correct answer: 3
B and C
B and C are correct statements about constructors in C#.NET.
在类中不需要构造函数。
构造函数用于初始化类的数据成员。
构造函数名称和类名称必须相同。
承包商是一种古老的技术,如今已经过时了。
选项:
正确答案:3
B和C
B和C是有关C#.NET中构造函数的正确声明。
A constructor does not have any return type.
Constructors can be overloaded.
Constructors cannot be overloaded.
A constructor is called when an object of the class gets created.
Options:
Correct answer: 3
Only C
Only C statement is not correct about construct in C#.NET.
构造函数没有任何返回类型。
构造函数可以重载。
构造函数不能重载。
创建类的对象时,将调用构造函数。
选项:
正确答案:3
只有C
关于C#.NET中的构造,仅C语句是不正确的。
Correct answer: 1
Method
In C#.NET, a constructor is a special type of method, which is used to initialize data members of a class.
Correct answer: 1
Yes
Yes it is true.
Correct answer: 1
Yes
Yes it is true.
Correct answer: 3
Only One time.
A constructor is called only one time when an object gets created.
正确答案:3
只有一次。
创建对象时,只会一次调用构造函数。
Correct answer: 1
Yes
Yes it is true.
Correct answer: 4
Body Constructor
In C#.NET, Body constructor is not a type of constructor.
正确答案:4
身体构造器
在C#.NET中,主体构造函数不是构造函数的一种。
A constructor is used to write code in a simple manner.
A class can contain multiple destructors.
A constructor is basically used to set default values in data members associated with an object.
A copy constructor is used in C#.NET
Opyions:
Correct answer: 2
C and D
In the above statements, only C and D statements are correct.
构造函数用于以简单的方式编写代码。
一个类可以包含多个析构函数。
构造函数基本上用于在与对象关联的数据成员中设置默认值。
在C#.NET中使用复制构造函数
py
正确答案:2
C和D
在以上语句中,只有C和D语句正确。
Correct answer: 2
No
No, we cannot pass any parameter to the destructor.
Correct answer: 3
Destructor
In C#.NET, the tilde (~) operator is used with a destructor.
正确答案:3
析构函数
在C#.NET中,波浪号(〜)运算符与析构函数一起使用。
A destructor is a special type of method, it automatically invokes when an object of the class gets destroyed.
We need to use a tilde (~) operator to define a destructor.
A destructor is used to reload the data member's value.
We can create multiple destructors in a class.
Options:
Correct answer: 2
A and B
析构函数是一种特殊的方法,当销毁该类的对象时,它将自动调用。
我们需要使用波浪号(〜)运算符来定义析构函数。
析构函数用于重新加载数据成员的值。
我们可以在一个类中创建多个析构函数。
选项:
正确答案:2
A和B
Correct answer: 1
Yes
Yes it is true.
Correct answer: 3
It does not have any return type
A destructor does not have any return type.
using System;
public class Example
{
int X;
int Y;
public static Example()
{
X = 10;
Y = 10;
}
public void show()
{
Console.WriteLine(X + " " + Y);
}
static void Main(string[] args)
{
Example Ob = new Example();
Ob.show();
}
}
Correct answer: 4
Syntax Error
We cannot use "static" keyword constructor.
using System;
public class Example
{
int X;
int Y;
public example()
{
X = 10;
Y = 10;
}
public void show()
{
Console.WriteLine(X + " " + Y);
}
static void Main(string[] args)
{
Example Ob = new Example();
Ob.show();
}
}
Correct answer: 4
Syntax Error
C# is a case sensitive language, in the above program constructor name is different from the class name.
public class Example
{
int X;
int Y;
public Example(int x, int y)
{
X = x;
Y = y;
}
}
Correct answer: 3
Example E = new Example(10,20);
3rd option is the correct way to create an object of a given class.
正确答案:3
例E =新例(10,20);
第三个选项是创建给定类的对象的正确方法。
Employee E1 = new Employee ("Shaurya");
Employee E2 = new Employee ("Shaurya", 5);
Code 1:
Code 2:
public Employee(int a)
{
name = "shaurya";
age = a;
}
public Employee(string n, int a)
{
name = n;
age = a;
}
Code 3:
Code 4:
public Employee(int a)
{
name = "shaurya";
age = a;
}
public Employee(int n, sting a)
{
name = n;
age = a;
}
Correct answer: 1
Code 1
The Code 1 is the correct way to define constructors.
代码1:
public Employee ( string n )
{
name = n ;
age = 5 ;
}
public Employee ( string n , int a )
{
name = n ;
age = a ;
}
代码2:
代码3:
public Employee ( )
{
name = " shaurya " ;
age = 5 ;
}
public Employee ( string n , int a )
{
name = n ;
age = a ;
}
代码4:
正确答案:1
代码1
代码1是定义构造函数的正确方法。
Correct answer: 1
Yes
Yes it is true.
Correct answer: 2
No
We cannot use the private keyword to define a destructor of the class.
Correct answer: 2
No
We cannot use the public keyword to define a destructor of the class.
A copy constructor is an old technique, it is deprecated nowadays.
A copy constructor is not supported in C#.NET.
A copy constructor is used to initialize an object from an existing object.
A copy constructor is also known as a no-argument constructor.
Options:
Correct answer: 4
Only C
Only C statement is correct about copy constructor.
复制构造函数是一种古老的技术,如今已不推荐使用。
C#.NET不支持复制构造函数。
复制构造函数用于从现有对象初始化对象。
复制构造函数也称为无参数构造函数。
选项:
正确答案:4
只有C
关于复制构造函数,只有C语句正确。
Correct answer: 1
Default constructor
A default constructor is also known as a no-argument constructor.
using System;
class Employee
{
string name;
int age;
public Employee()
{
name = "shaurya";
age = 5;
}
public Employee(Employee E)
{
name = E.name;
age = E.age;
}
public void show()
{
Console.WriteLine(name + " " + age);
}
static void Main(string[] args)
{
Employee e1 = new Employee();
Employee e2 = new Employee(e1);
e1.show();
e2.show();
}
}
Correct answer: 1
shaurya 5
shaurya 5
1st option is the correct answer for the code snippets.
using System;
class Employee
{
string name;
int age;
public Employee()
{
this.name = "shaurya";
age = 5;
}
public Employee(Employee E)
{
name = E.name;
this.age = E.age;
}
public void show()
{
Console.WriteLine(name + " " + age);
}
static void Main(string[] args)
{
Employee e1 = new Employee();
Employee e2 = new Employee(e1);
e1.show();
e2.show();
}
}
Correct answer: 1
shaurya 5
shaurya 5
1st option is the correct answer for the code snippets.
c# 构造函数 析构函数