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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T01:04:28+00:00 2026-05-30T01:04:28+00:00

I’ve been teaching myself C#, and I’m just learning how to use custom data

  • 0

I’ve been teaching myself C#, and I’m just learning how to use custom data types. The program I’m writing produces a bunch of pairs of coordinate pairs. I thought it’d be a neat idea to create a data type that holds each set (x1, x2, y1, y2), along with a few other variables pertaining to that set. However, the program will produce more than one array of coordinates sets (different categories), so keeping track of things was still difficult. I then broke it down further into categories, and placed each category under a third type that acts as a third level, which is then put into a list.

Each “tier” of items has some properties specific to that tier, but prior to this roadblock I didn’t have any need to swap data among the hierarchy. The problem arose when I realized that I needed to modify the coordinate pair sets using an offset, and each offset is specific to the parent data type. I can modify the get{} code to return the data plus the offset (I called it “skew”), but not if the offset is from outside the data type’s class itself. I tried setting a value in the parent data type (even a public static one), but the child couldn’t read it for some reason.

The only way I know how to make this work is by setting the property in each coordinate set, but there could be thousands of them. The value is unique to the parent, but all the children need to use it, so that seems wasteful, given that there will be a lot of other calculations going on. My other thought was to maintain an offset array, and add it to the places where the values are retrieved. But, that isn’t as clean as containing it within the data type itself, and so it will add to the confusion. Is there another method of accomplishing this?

Here is how some of the code looks:

public class SlotData
    {
        private double _x1, _x2, _y1, _y2;

        public double X1
        {
            get { return _x1; }
            set { _x1 = value; }
        }
        public double X2
        {
            get { return _x2; }
            set { _x2 = value; }
        }
        public double Y1
        {
            get { return _y1; }
            set { _y1 = value; }
        }
        public double Y2
        {
            get { return _y2; }
            set { _y2 = value; }
        }
    }
public class ClientInfo
    {
        public static double _skewX, _skewY;

        public SlotGroup1 Group1
        {
            get;
            set;
        }
        public SlotGroup2 Group2
        {
            get;
            set;
        }
        public SlotGroup3 Group3
        {
            get;
            set;
        }
    }

public class SlotGroup1
    {
        public SlotData Slot1
        {
            get;
            set;
        }
        public SlotData Slot2
        {
            get;
            set;
        }
    }
  • 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-30T01:04:29+00:00Added an answer on May 30, 2026 at 1:04 am
        public class SlotData
        {
            private SlotData() { }
            public SlotData(SlotGroupBase group) 
            {
                this._group = group;
            }
    
            private SlotGroupBase _group;
    
            public double X1 { get; set; }
            public double X2 {get; set;}
            public double Y1 {get; set;}
            public double Y2 {get; set;}
    
            public double NewX1 
            {
                get
                {
                    return _group.ClientInfo._skewX + X1;
                }
            }
        }
    
        public class ClientInfo
        {
            public double _skewX, _skewY;
    
            public SlotGroup1 Group1 { get; set; }
        }
    
        public abstract class SlotGroupBase
        {
            private SlotGroupBase() { }
            public SlotGroupBase(ClientInfo ci) 
            {
                this._ci = ci;
            }
    
            private ClientInfo _ci;
    
            public ClientInfo ClientInfo
            {
                get
                {
                    return _ci;
                }
            }            
        }
    
        public class SlotGroup1 : SlotGroupBase
        {
            public SlotGroup1(ClientInfo ci):base (ci) {}
            public SlotData Slot1 { get; set; }
            public SlotData Slot2 { get; set; }
        }
    
        static void Main(string[] args)
        {
            ClientInfo ci = new ClientInfo();
            SlotGroup1 sg1 = new SlotGroup1(ci);
            sg1.Slot1 = new SlotData(sg1);
            sg1.Slot2 = new SlotData(sg1);
            Console.ReadLine();
        }
    

    In your code you don’t have either parent or descendant data types. So, members of some type couldn’t be accessible to other types in any way other than you will have reference to an instance of object of some type.

    But object-oriented programming could help you. In case if each from SlotGroupN types must have reference to ClientInfo, it would be worthwhile to have base class SlotGroupBase which will contain reference to ClientInfo. Also you should add to SlotData type reference to SlotGroupBase. In this case you will access your skews like

    return _group.ClientInfo._skewX + X1;
    

    Another good idea is to restrict yourself and other developers from creation SlotGroupN class instances without reference to ClientInfo, SlotData class item without reference to SlotGroup. To achieve this you should make default constructors private and add constructor with parameter ClientInfo

    public SlotGroupBase(ClientInfo ci) 
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a jquery bug and I've been looking for hours now, I can't
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have just tried to save a simple *.rtf file with some websites and
I am trying to understand how to use SyndicationItem to display feed which is
I want use html5's new tag to play a wav file (currently only supported
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I want to construct a data frame in an Rcpp function, but when I
I'm trying to use string.replace('’','') to replace the dreaded weird single-quote character: ’ (aka
I am writing an app with both english and french support. The app requests

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.