Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6988053
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T19:01:18+00:00 2026-05-27T19:01:18+00:00

This is essentially what I want to do: public abstract class Uniform<T> { public

  • 0

This is essentially what I want to do:

public abstract class Uniform<T>
{
    public readonly int Location;
    private T _variable;

    public virtual T Variable
    {
        get { return _variable; }
    }
}

public class UniformMatrix4 : Uniform<Matrix4>
{
    public override Matrix4 Variable
    {
        set
        {
            _variable = value;
            GL.UniformMatrix4(Location, false, ref _variable);
        }
    }
}

The getter for Variable will be the same across all derived classes, but the setter needs to be different.

In fact… I’d prefer not to have derived classes at all (it’s only one function call that will differ for each type) but I can’t think of how else to do it.


Edit: If it wasn’t clear what the problem I’m having is, I’m getting a syntax error:

‘UniformMatrix4.Variable.set’: cannot override because ‘Uniform.Variable’ does not have an overridable set accessor

And I’m not sure how to create an “overridable set accessor”… virtual and abstract don’t seem to be allowed on the setter.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T19:01:19+00:00Added an answer on May 27, 2026 at 7:01 pm

    It’s not possible to do this in C#, but as a workaround you could do this. It would involve calling an abstract setter function which could be overridden by derived classes, while leaving the standard get intact. Would this work?

    public abstract class Uniform<T>
    {
        public readonly int Location;
        protected T _variable;
    
        public T Variable
        {
            get { return _variable; }
            set { SetVariable(value); } 
        }
    
        protected abstract void SetVariable(T value);
    }
    
    public class UniformMatrix4 : Uniform<Matrix4>
    {
        public override void SetVariable(Matrix4x4 value)
        {
            _variable = value;
            GL.UniformMatrix4(Location, false, ref _variable);
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Lets say I have this class class Child { public string FirstName { get;
I have a base class like this: class FooBase { public bool Do(int p)
I want to have an abstract class Server with an abstract method called Initialize
Consider the following function: public function foo(bar1:int, bar2:uint, bar3:String, bar4:Boolean):void{} What I want is
I essentially want to do this: if(obj is IDictionary) { return { + string.Join(Environment.NewLine,
My AJAX-enabled WCF service returns JSON using this contract, [DataContract] public class JQGridContract {
So in this section of code I have, I want to essentially tell the
I have a generic class that essentially extends a linq class. This means that
I have a class declared as such: public abstract class CrmAttribute <T> : ICrmAttribute
How can I fix this: class Name { public void createArray(String name) { String

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.