什么是功能的"这"在构造函数中的关键字? [英] What is the function of the "this" keyword in a constructor?
本文介绍了什么是功能的"这"在构造函数中的关键字?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我是看着从MSDN样本code刚才来到翻过:
命名空间IListSourceCS
{
公共类员工:BusinessObjectBase
{
私人字符串_id;
私人字符串_name;
私人十进制parkingId;
公务员():这个(的String.Empty,0){} //<< ---这是什么???
公务员(字符串名称):这个(姓名,0){}
解决方案
它调用该类与签字的另一构造。它的方式来实现的构造函数在其他构造的条款。 基础
也可以用来调用基类的构造函数。你必须有匹配该为它工作签名的构造函数。
I was looking at sample code from MSDN just now and came accross:
namespace IListSourceCS
{
public class Employee : BusinessObjectBase
{
private string _id;
private string _name;
private Decimal parkingId;
public Employee() : this(string.Empty, 0) {} // <<--- WHAT IS THIS???
public Employee(string name) : this(name, 0) {}
解决方案
It calls the other constructor in that class with that signature. Its a way of implementing the constructor in terms of other constructors. base
can also be used to call the base class constructor. You have to have a constructor of the signature that matches this for it to work.
这篇关于什么是功能的&QUOT;这&QUOT;在构造函数中的关键字?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文