I have a struct for saving some faked "weather" data. So i want to store a random number as measure value and the date + time it was measured. My teacher told me to use a custom constructor so that i can give the values when creating a new one. So far so good but when i did it Visual Studio marked me the first value in the master constructor as error.
The error is :
PHP Code:
The this object can only be used when all fields have been assigned.
PHP Code:
struct WeatherData
{
private int _fakeValue;
private string _fakeDate;
// getter und setter for the privat members
public int FakeValue
{
get { return _fakeValue; }
set { _fakeValue = value; }
}
public string FakeDate
{
get { return _fakeDate; }
set { _fakeDate = value; }
}
// overrides the inherited ToString method with my own version
public override string ToString()
{
return String.Format("Wert: {0}, gemessen am: {1}", FakeValue, FakeDate);
}
public WeatherData(int value)
:this(value, DateTime.Now.ToString()){}
public WeatherData(string date)
:this(0, date){}
// here is the error but i don't know why...
public WeatherData(int value, string date)
{
this.FakeValue = value;
this.FakeDate = date;
}
}
And if you have any ideas of making it better just tell me
desTenshi
ps:
This whole program is a school project i got from my teacher, so don't say something about the topic of it xD ...






