I know it's cumbersome, but what about this:

public class ALessThanB
{
        private bool    m_bASet = false, m_bBSet = false;
        private int             m_nA = 0, m_nB = 0;

        public int A {
                set {
                        if(m_bBSet && value >= m_nB)
                                throw new ArgumentException("A must be less
than B.");
                        m_nA = value;
                        m_bASet = true;
                }
        }
        public int B {
                set {
                        if(m_bASet && value <= m_nA)
                                throw new ArgumentException("B must be
greater than A.");
                        m_nB = value;
                        m_bBSet = true;
                }
        }
}

-----Original Message-----
From: Simon Robinson [mailto:[EMAIL PROTECTED]]
Sent: Friday, May 17, 2002 11:01 AM
To: [EMAIL PROTECTED]
Subject: [DOTNET] Setting properties


Hi guys

I have a class with two integer properties - call them A and B.
There is a condition that the value of B should always be greater than A,
otherwise the class won't function correctly. I'd like the error to be
detected and an exception thrown when client code sets the properties,
and I'm trying to figure out if there's any way of doing this that's
consistent with the normal .NET usage guidelines that it should be
acceptable to set
properties in any order.

Any ideas? Is what I want to do possible?

Simon

---------------------------------------------------------------
Simon Robinson
http://www.SimonRobinson.com
---------------------------------------------------------------

You can read messages from the DOTNET archive, unsubscribe from DOTNET, or
subscribe to other DevelopMentor lists at http://discuss.develop.com.

You can read messages from the DOTNET archive, unsubscribe from DOTNET, or
subscribe to other DevelopMentor lists at http://discuss.develop.com.

Reply via email to