对象和构造函数有什么区别 [英] what is the difference between object and constructor

查看:211
本文介绍了对象和构造函数有什么区别的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

对象和构造函数之间的区别是什么?

what is the difference between object and constructor

推荐答案

请参见以下代码:
See the below code:
Public class Employee
{
   int Id;
   string Name;

   public Employee(int Id)
   {
     this.Id = Id;
   }
}

Employee emp = new Employee(1);



在下面的代码中,emp是对象,它保存员工的实例.



In the below code emp is the object, it holds instance of the employee.

public Employee(int Id)



上一行是构造函数,用于在创建对象时初始化对象.



The above line is the constructor, which is used to initialize object while creation.


您无法通过这种方式比较这两件事.

实际上,构造函数会初始化对象
You can''t compare these two things by this way.

Actually Constructor initializes the Objects


这篇关于对象和构造函数有什么区别的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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