I have a class defined that I am going to be assigning to a PropertyGrid. The class is defined as a normal class with properties, but one of the properties is another class. This worked just fine in Visual Basic, but in C# I get an error on the line that has the inclusion of the other class.
The errors are:
Error 1 Invalid token '=' in class, struct, or interface member declaration
Error 2 Invalid token '(' in class, struct, or interface member declaration
The corresponding line in the original VB.Net code is:
Any ideas on why it won't compile in C#?
Class within a class:
namespace ATE_Lab
{
public enum TemperatureDeviceName
{
Thermotron2800,
Thermotron3800,
Sun,
InfraredScanner,
WatlowF4,
EZT570i,
ESPEC
}
public enum TemperatureScale
{
Celsius,
Fahrenheit
}
public class TemperatureDevice
{
private float _SetPoint = 25f;
private bool _IsController = true;
private TemperatureDeviceName _DeviceName = TemperatureDeviceName.Thermotron2800;
private string _ErrorMessage = "";
private bool _Control = true;
private short _SoakTime = 0;
private float _MinTemperature = 0f;
private float _MaxTemperature = 0f;
[CategoryAttribute("Device")]
[DefaultValue(typeof(TemperatureDeviceName), "Thermotron2800")]
[DescriptionAttribute("Device name of the communication device")]
public TemperatureDeviceName DeviceName
{
get
{
return _DeviceName;
}
set
{
switch (value)
{
case TemperatureDeviceName.InfraredScanner:
_IsController = false;
break;
case TemperatureDeviceName.WatlowF4:
ProtocolSetup.Address = 1;
ProtocolSetup.CommPort.Parity = System.IO.Ports.Parity.None;
break;
case TemperatureDeviceName.EZT570i:
ProtocolSetup.Address = 1;
ProtocolSetup.CommPort.Parity = System.IO.Ports.Parity.Even;
break;
default:
_IsController = true;
break;
}
_DeviceName = value;
}
}
[CategoryAttribute("Setup")]
[DefaultValue(typeof(TemperatureScale), "Celsius")]
[DescriptionAttribute("Scale of the communication device")]
public TemperatureScale Scale { get; set; }
[CategoryAttribute("Setup")]
[DescriptionAttribute("Communication protocol of the device")]
public ATE_Lab.CommSetup ProtocolSetup { get; set; } = new ATE_Lab.CommSetup();
The errors are:
Error 1 Invalid token '=' in class, struct, or interface member declaration
Error 2 Invalid token '(' in class, struct, or interface member declaration
The corresponding line in the original VB.Net code is:
VB.Net original code:
Public Property ProtocolSetup As New CommSetup
Any ideas on why it won't compile in C#?