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 4249368
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T04:23:16+00:00 2026-05-21T04:23:16+00:00

The example I am giving is not exactly what I’m working on, but its

  • 0

The example I am giving is not exactly what I’m working on, but its is an approximate representation and greatly simplified to the exact problem. I am willing to investigate all options.

I have an abstract class with a data value I want to override in a subsequent class.

The base abstract class

public abstract class Variable
{
    public abstract long data;
}

I have a subclass

public class FloatVariable : Variable
{
    public override float data;
}

However when using late dynamic binding I have trouble

Variable var = new FloatVariable();
var.data = 0.33f;

Causes an error that it “Cannot implicitly convert type ‘float’ to ‘long'”

Obviously I’m not doing it right, however if there is a way to override variables (and types) so that late dynamic binding will still allow it to compile, it would make my life infinity easier.

  • 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-21T04:23:17+00:00Added an answer on May 21, 2026 at 4:23 am

    I found a solution that solves my problem that I could not resolve with generics/templates.

    Create a new scalar class

    Class Scalar
    {
        private byte dataByte = 0;
        private short dataShort = 0;
        // ... int, long, float, double
        private string dataString = 0;
        private List<Variable> dataList = null;
    
        //constructors for "later" type casting (see below)
        public Scalar(byte data)
        {
            this.dataByte = data;
        }
    
        //* repeat this for short, int, long, float, double, string, List<>
    
        //implicit conversions for getting data out
        public static implicit operator byte(Scalar scalar)
        {
            return scalar.dataByte;
        }
    
        //* repeat this for short, int, long, float, double, string, List<>
    
        //implicit conversions for getting data in (invokes a constructor)
        public static implicit operator Scalar(byte data)
        {
            return new Scalar(data);
        }
    
        //* repeat this for short, int, long, float, double, string, List<>
    }
    

    Then create my base variable class

    abstract class Variable
    {
        public Scalar Data
        {
            get { return data; }
            set { data = value; }
        }
    
        protected Scalar data = new Scalar(0);
    
        /* other meta information etc */
    }
    

    Then create your sub classes of your meta variables

    class MetaByte : Variable
    {
        public byte Data
        {
            get { return data; }
            set { data = value; }
        }
    
        /* byte specific features */
    }
    

    Then using it works just fine with dynamic binding

    Variable scalar = new MetaByte();
    scalar.Data = 33;
    scalar = new MetaList();
    scalar.Data = new List<Variable>();
    

    Its not perfect with the lists, but it seems to work for how I intend to use it.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

C# is still not OO enough? Here I'm giving a (maybe bad) example. public
Update: giving a much more thorough example. The first two solutions offered were right
I have a scenario which I think I can convey giving PC Monitor example
People keep giving me examples with carp instead of warn. Why? What makes carp
Example: You have a shortcut s to SomeProgram in the current directory. In cmd.exe
Example I have Person , SpecialPerson , and User . Person and SpecialPerson are
Example: select ename from emp where hiredate = todate('01/05/81','dd/mm/yy') and select ename from emp
example: a_list = [1, 2, 3] a_list.len() # doesn't work len(a_list) # works Python
example: I want to see if array[5] holds a value or is empty.
Example C API signature: void Func(unsigned char* bytes); In C, when I want to

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.