[英]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.