Adalat  Khan

Adalat Khan

  • 652
  • 1.5k
  • 866.7k

Class Properties value selection

Sep 2 2021 8:17 AM

Hi,

How we can select the value of one property on the basis of another property value Enumeration. Following is my Senario:

public BaseTypeValue MyBaseTypeValue { get; set; }
public NumberValue MyNumberValue { get; set; }
public ValueType MyValueType { get; set; }
Public Enum BaseTypeValue
{
ABC,
DEF
}
Public Enum NumberValue
{
123,
456
}
Public Enum ValueType
{
7.5,
2.5
}

I have three properties MyBaseTypeValuee, MyNumberValue, and MyValueType of types Enumerations respectively. Now I want if someone selects the value of MyBaseTypeValue property then the next two property values are automatically selected on the bases of MyBaseTypeValue. Following is the condition:

If(MyBaseTypeValue == BaseTypeValue.ABC )
{
    MyNumberValue = NumberValue.123;
    MyValueType = ValueType.7.5;
}
else
{
    MyNumberValue = NumberValue.456;
    MyValueType = ValueType.2.5;
}

How we can implement this logic in the Model (C# Model Class)?


Answers (2)