[英]How to override base class constructor in C#
如何使用 Visual Studio 覆盖 C# 中的基本 class 构造函数,我尝试调用它,但编译器报告错误MyGLSurfaceView
不包含采用 0 arguments 的构造函数,但在构造函数实现中有一个参数。
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Android.App;
using Android.Content;
using Android.Opengl;
using Android.OS;
using Android.Runtime;
using Android.Views;
using Android.Widget;
namespace Painting
{
class MyGLSurfaceView : GLSurfaceView
{
Context mycontext;
private readonly MyGlRenderer render;
// Constructor with one argument
// Compiler reports an error saying this constructor does not take 0 arguments
public MyGLSurfaceView(Context context)
{
//
}
}
}
您不能覆盖基本 class 构造函数。
在@The General 评论了一个答案之后,这对我有用,因为 Android 中的某些类是抽象的,不能像 Android.Os.CountDownTimer 那样直接实例化,所以当从它们继承时,构造函数成为一个问题,但这解决了它我暂时...
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Android.App;
using Android.Content;
using Android.Opengl;
using Android.OS;
using Android.Runtime;
using Android.Views;
using Android.Widget;
namespace Painting
{
class MyGLSurfaceView : GLSurfaceView
{
Context mycontext;
private readonly MyGlRenderer render;
// Constructor with one argument
// Compiler reports an error saying this constructor does not take 0 arguments
public MyGLSurfaceView(Context context) : base (context) { ...}
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.