[英]c sharp equivalent on java constructor
Not sure if my title is correct. 不确定我的标题是否正确。 Forgot what it is code.
忘了代码是什么。 But here i will explain it through code.
但在这里,我将通过代码解释它。
you see in java you can declare a class like this. 你在java中看到你可以声明一个这样的类。
class Panel extends View{
public Bitmap mBitmap;
public Panel(Context context) {
super(context);
}
}
in c sharp 在c sharp
class Panel : View
{
public Panel(Context context){
base(context);
}
}
it has an error. 它有一个错误。 how do you declare a class constructor like that in csharp?
你如何在csharp中声明类构造函数?
class Panel : View
{
public Panel(Context context) : base(context)
{
}
}
MSDN: Using Constructors (C# Programming Guide) MSDN:使用构造函数(C#编程指南)
In C#, calling the base constructor is a bit more explicit (or rather explicitly separate) 在C#中,调用基础构造函数更明确(或者更明确地分开)
While in Java it would look like just any statement that could be reordered with the other statements in the body, it's moved outside the normal constructor body in C#. 在Java中,它看起来就像任何可以与正文中的其他语句重新排序的语句,它被移动到C#中的普通构造函数体之外。
class Panel : View
{
public Panel(Context context) : base(context) { }
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.