The following code seems to be impossible to compile no matter how hard I am trying to cast it :P can somone please tell me what I am doing wrong?
public class LUOverVoltage
{
public string Name { get; set; }
public enum OVType { OVLH, OVLL }
public List<string> PinGroups = new List<string>();
public void Add(string name, OVType type, string Grp)
{
this.Name = name;
this.OVType = type; //Why cannot reference a type through an expression?
PinGroups.Add(Grp);
}
}
You're confusing a field that has an enum type with the enum type itself. Your code is about as useful as saying string="bla"
.
public enum OVType { OVLH, OVLL }
public class LUOverVoltage
{
public string Name { get; set; }
public OVType OVType { get; set; }
This declares a type called OVType
and a property with the same name. Now your code should work.
As a side note, both your type names, and the property names violate .net naming guidelines.
I'd name the enum type OverVoltKind
and the property just Kind
.
You're not setting a property, you're trying to set the enum.
Add a public OVType ovType
and use this.ovType = type
.
public class LUOverVoltage
{
public enum OVType { OVLH, OVLL }
public string Name { get; set; }
public OVType ovType;
public List<string> PinGroups = new List<string>();
public void Add(string name, OVType type, string Grp)
{
this.Name = name;
this.ovType = type;
PinGroups.Add(Grp);
}
}
You have defined an Enum
inside your class. What you have not done is declare a variable to hold an instance of that enum.
public enum OVType { OVLH, OVLL }
public class LUOverVoltage
{
public string Name { get; set; }
public OVType OVType { get; set; }
public List<string> PinGroups = new List<string>();
public void Add(string name, OVType type, string Grp)
{
this.Name = name;
this.OVType = type; // setting the property, not the enum definition
PinGroups.Add(Grp);
}
}
OVType - is not a field, its a type
Try this
public class LUOverVoltage
{
public string Name { get; set; }
public OVType Type {get; set;}
public enum OVType { OVLH, OVLL }
public List<string> PinGroups = new List<string>();
public void Add(string name, OVType type, string Grp)
{
this.Name = name;
this.Type = type;
PinGroups.Add(Grp);
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With