我需要在c#中解释这些行 [英] I Need the explanation of these lines in c#

查看:77
本文介绍了我需要在c#中解释这些行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这里我提到了4行。请解释代表该行的内容。



假设员工是班级。



员工a​​;

新员工;

a =新员工();

员工b =新员工();

解决方案

第一个语句创建一个引用变量以键入Employee

第二个和第三个语句在语法上不正确

第四个语句创建一个Employee类型的对象

查看代码的基本说明:

员工a;

It ''员工类型的简单变量声明。



新员工();

调用Employee类的构造函数(初始化Employee类)。



e =新员工();

在堆上创建对象并调用Employee类的构造函数。对象e必须是一种Employee类。



员工b =新员工();

在堆上创建Employee类的对象并调用默认构造函数。



希望它有所帮助!

- 阿米特

Here i mentioned 4 lines. please explain what are represents that lines.

Assume Employee is the class.

Employee a;
new Employee;
a=new Employee();
Employee b=new Employee();

解决方案

First statement creates a reference variable to type Employee
Second and third statements are syntactically incorrect
Fourth statement creates a object of type Employee


See the basic explanation of your code:
Employee a;
It''s a simple variable declaration of Employee type.

new Employee();
Invoking constructor of Employee class(Initializing Employee class).

e = new Employee();
Create object on the heap and invoke constructor of Employee class. Object e must be a type of Employee class.

Employee b = new Employee();
Creating the object of Employee class on heap and invoking the default constructor.

Hope it helps!
--Amit


这篇关于我需要在c#中解释这些行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆