这是什么冒号(:)是什么意思? [英] What does this colon (:) mean?
本文介绍了这是什么冒号(:)是什么意思?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在此关键字是一个冒号。什么谁能解释一下这个冒号在这方面意味着什么?我不相信这是inhertance。
感谢
使用系统;命名空间LinkedListLibrary
{
类ListNode
{
私有对象的数据;
接下来的私人ListNode; 公共ListNode(对象dataValue)
:这个(dataValue,NULL)
{
} 公共ListNode(对象dataValue,ListNode nextNode)
{
数据= dataValue;
接下来= nextNode;
} 公共ListNode下一页
{
得到
{
返回下一个;
}
组
{
接下来=价值;
}
}
公共对象数据
{
得到
{
返回的数据;
}
}
}
}
解决方案
这(与这个
关键字一起)指示构造函数调用同类型中的另一个构造在它之前,自己执行。
因此:
公共ListNode(对象dataValue)
:这个(dataValue,NULL)
{
}
实际上变成:
公共ListNode(对象dataValue)
{
数据= dataValue;
接下来= NULL;
}
请注意,您可以使用基
而不是这个
来指示构造函数调用基类的构造函数
Before the this keyword is a colon. What can anyone explain what this colon means in this context? I don't believe this is inhertance.
Thanks
using System;
namespace LinkedListLibrary
{
class ListNode
{
private object data;
private ListNode next;
public ListNode(object dataValue)
: this(dataValue, null)
{
}
public ListNode(object dataValue, ListNode nextNode)
{
data = dataValue;
next = nextNode;
}
public ListNode Next
{
get
{
return next;
}
set
{
next = value;
}
}
public object Data
{
get
{
return data;
}
}
}
}
解决方案
It (along with the this
keyword) is instructing the constructor to call another constructor within the same type before it, itself executes.
Therefore:
public ListNode(object dataValue)
: this(dataValue, null)
{
}
effectively becomes:
public ListNode(object dataValue)
{
data = dataValue;
next = null;
}
Note that you can use base
instead of this
to instruct the constructor to call a constructor in the base class.
这篇关于这是什么冒号(:)是什么意思?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文