这个冒号 (:) 是什么意思? [英] What does this colon (:) mean?
本文介绍了这个冒号 (:) 是什么意思?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
this
关键字之前是一个冒号.任何人都可以解释冒号在这种情况下的含义吗?我不相信这是继承.
Before the this
keyword is a colon. Can anyone explain what the colon means in this context? I don't believe this is inhertance.
谢谢
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;
}
}
}
}
推荐答案
它(连同 this
关键字)指示构造函数在它自己执行之前调用同一类型中的另一个构造函数.
It (along with the this
keyword) is instructing the constructor to call another constructor within the same type before it, itself executes.
因此:
public ListNode(object dataValue)
: this(dataValue, null)
{
}
实际上变成:
public ListNode(object dataValue)
{
data = dataValue;
next = null;
}
请注意,您可以使用 base
而不是 this
来指示构造函数调用基类中的构造函数.
Note that you can use base
instead of this
to instruct the constructor to call a constructor in the base class.
这篇关于这个冒号 (:) 是什么意思?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文