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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T04:15:22+00:00 2026-06-17T04:15:22+00:00

I’ve been working on some electrical network simulation software ( ElecNetKit ). In electrical

  • 0

I’ve been working on some electrical network simulation software (ElecNetKit). In electrical networks, sometimes it’s convenient to work with single-phase models, sometimes in three-phase models.

As such, I would like to be able to represent one of the electrical network elements as:

class Bus
{
    public Complex Voltage {set; get;} //single phase property
}

but simultaneously in a fashion so that the user can call Bus.Voltage.Phases[x], and expect a Complex for any valid integer x.

The Bus.Voltage property should map to Bus.Voltage.Phases[1] when treated as a Complex.

I’ve got two questions here:

  1. Is this in violation of any OOP principles? I’ve got a feeling that it might be.
  2. Is there a convenient way to represent this in C#?

In terms of representation, I’ve tried:

  • a class Phased<T> : T, but this is incompatible with the typing system, and
  • a class Phased<T> with a generic converter to type T, but the converter still needs to be invoked.

I’m aware that I can simply use something like:

public Dictionary<int,Complex> VoltagePhases {private set; get;}
public Complex Voltage {
    set {VoltagePhases[1] = value;} 
    get {return VoltagePhases[1];}
}

but there’s a lot of repetition once you start to do this for multiple properties, across multiple classes.

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

    I would propose something like this:

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.Threading;
    using System.Diagnostics;
    using System.Numerics;
    
    namespace Test
    {
        class PhaseList
        {
            private Dictionary<int, Complex> mPhases = new Dictionary<int, Complex>();
    
            public Complex this[int pIndex]
            {
                get
                {
                    Complex lRet;
                    mPhases.TryGetValue(pIndex, out lRet);
                    return lRet;
                }
                set
                {
                    mPhases.Remove(pIndex);
                    mPhases.Add(pIndex, value);
                }
            }
        }
    
        class PhasedType
        {
            private PhaseList mPhases = new PhaseList();
            public PhaseList Phases { get { return mPhases; } }
            public static implicit operator Complex(PhasedType pSelf)
            {
                return pSelf.Phases[1];
            }
    
            public static implicit operator PhasedType(Complex pValue)
            {
                PhasedType lRet = new PhasedType();
                lRet.Phases[1] = pValue;
                return lRet;
            }
        }
    
        class Bus
        {
            public PhasedType Voltage { get; set; }
        }
    
        class Program
        {
            static void Main(string[] args)
            {
                Bus lBus = new Bus();
    
                lBus.Voltage = new Complex(1.0, 1.0);
                Complex c = lBus.Voltage;
                lBus.Voltage.Phases[1] = c;
                c = lBus.Voltage.Phases[1];
            }
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm working with an upstream system that sometimes sends me text destined for HTML/XML
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
For some reason, after submitting a string like this Jack’s Spindle from a text
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I have been unable to fix a problem with Java Unicode and encoding. The
I'm trying to convert HTML to plain text. I get many &\#8217; &\#8220; etc.
I'm trying to use string.replace('’','') to replace the dreaded weird single-quote character: ’ (aka
I'm trying to create an if statement in PHP that prevents a single post

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.