问题描述
如何使用 Visual Studio 覆盖 C# 中的基类构造函数,我尝试调用它,但编译器报告错误 MyGLSurfaceView
不包含采用 0 个参数的构造函数,但我在构造函数实现请帮忙..
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)
{
//
}
}
}
解决方法
您不能覆盖基类构造函数。
,@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) { ...}
}
}