C#调用基类构造函数 [英] C# Calling Base Class Constructor
本文介绍了C#调用基类构造函数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
public CArm(Vector3 at, string name) : base(name)
{
}
有没有其他方法在括号中调用基础父构造函数,而不是:base(name)
?
Is there any other way to call base parent constructor within the brackets instead of doing : base(name)
?
我不知道这是不是另一种语言,但我记得像 super();
I'm not sure if this was another language but I recall something like super();
inside of the constructor to call the base class.
推荐答案
不,你不能在C#中的构造函数体内调用基础构造函数。你可能想到Java的语法。
No, you cannot call base constructors inside constructor bodies in C#. You're probably thinking of Java's syntax.
您可以通过调用方法来模拟所需的行为。只要确保非常小心调用虚拟方法!
You can emulate the desired behavior by calling a method instead. Just make sure to be very careful about calling virtual methods!
这篇关于C#调用基类构造函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文