0

How do I override the base class constructor in C# with Visual Studio, i have tried calling this but compiler reports an error that MyGLSurfaceView does not contain a constructor that takes 0 arguments and yet I have an argument in the constructor implementation please help..

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)
        {
            //
        }
    }
}
atiyar
  • 7,762
  • 6
  • 34
  • 75
  • Why would Microsoft let people convert java to C# when doing android development and yet there is a huge difference in the constructor overriding logic? –  Mar 01 '21 at 06:30
  • I mean everything else done in java can be done with C# except constructor overriding? –  Mar 01 '21 at 06:30
  • 1
    have you tried `public MyGLSurfaceView(Context context) : base (context) { ...}` – TheGeneral Mar 01 '21 at 06:36
  • No i haven't let me try it –  Mar 01 '21 at 06:40
  • It worked thanks @General –  Mar 01 '21 at 06:44
  • 1
    Does this answer your question? [Is it possible to override a constructor in C#?](https://stackoverflow.com/questions/11271920/is-it-possible-to-override-a-constructor-in-c) – atiyar Mar 01 '21 at 06:49

2 Answers2

0

You can't override the base class constructors.

Jagdish Kumar
  • 225
  • 1
  • 4
  • 14
0

This worked for me after @The General commented an answer Its because certain classes in Android are abstract and cannot be instantiated directly like Android.Os.CountDownTimer, so when it comes to inherting from them, the constructor becomes a problem but this solved it for me for now...

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) { ...}
    }
}