📄 forecaster.cs
字号:
using System;
using System.Collections;
namespace WeatherLib
{
public enum Weather
{
Fair,
PartlyCloudy,
Cloudy,
Rain,
Snow,
Sleet,
Fog
}
public enum WindDirection
{
North,
NorthEast,
East,
SouthEast,
South,
SouthWest,
West,
NorthWest
}
public class Forecast
{
static Random gen = new Random ();
public Forecast (int daysAway)
{
// Okay, this is the cheap hack.
// Return totally random numbers:
HighTemp = gen.Next (0, 95);
LowTemp = HighTemp - gen.Next (5, 40);
WindSpeed = gen.Next (2, 80);
direction = (WindDirection) gen.Next (7);
prediction = (Weather)gen.Next (6);
DateTime predDay = DateTime.Today;
predDay = predDay.AddDays (daysAway);
forecastDate = predDay;
}
private decimal hi;
public decimal HighTemp
{
get
{
return hi;
}
set
{
hi = value;
}
}
private decimal lo;
public decimal LowTemp
{
get
{
return lo;
}
set
{
lo = value;
}
}
private int wind;
public int WindSpeed
{
get
{
return wind;
}
set
{
wind = value;
}
}
private WindDirection dir;
public WindDirection direction
{
get
{
return dir;
}
set
{
dir = value;
}
}
private Weather pred;
public Weather prediction
{
get
{
return pred;
}
set
{
pred = value;
}
}
private DateTime theDate;
public DateTime forecastDate
{
get
{
return theDate;
}
set
{
theDate = value;
}
}
}
/// <summary>
/// Summary description for Class1.
/// </summary>
public class WeatherForecast : IEnumerable
{
private class weatherEnum : IEnumerator
{
public weatherEnum (WeatherForecast coll)
{
Collection = coll;
}
int index=-1;
WeatherForecast Collection;
#region IEnumerator Members
public void Reset()
{
index = -1;
}
public object Current
{
get
{
return Collection[index];
}
}
public bool MoveNext()
{
++index;
return (index < Collection.Count);
}
#endregion
}
public WeatherForecast(string city)
{
//
// TODO: Add constructor logic here
//
}
int Count
{
get
{
return 10; // more than a five day forecast is pointless.
}
}
Forecast this [int daysAway]
{
get
{
return new Forecast (daysAway);
}
}
#region IEnumerable Members
public IEnumerator GetEnumerator()
{
return new weatherEnum (this);
}
#endregion
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -