Пример #1
0
        private static void SampleFour()
        {
            var data = new HistoricalWeatherData();

            data["Chicago", new DateTime(1970, 6, 6)] = new Measurements
            {
                HiTemp = 75,
                LoTemp = 58,
                AirPressure = 30.2
            };

            var item = data["Chicago", new DateTime(1970, 6, 6)];
            Console.WriteLine(item.HiTemp);
            item = data["Chicago", new DateTime(1970, 6, 6, 12, 30, 2)];
            Console.WriteLine(item.LoTemp);

            data["Chicago", new DateTime(1970, 6, 6)] = new Measurements
            {
                HiTemp = 85,
                LoTemp = 38,
                AirPressure = 30.2
            };

            item = data["Chicago", new DateTime(1970, 6, 6)];
            Console.WriteLine(item.HiTemp);
            item = data["Chicago", new DateTime(1970, 6, 6, 12, 30, 2)];
            Console.WriteLine(item.LoTemp);

            try
            {
                item = data["New York", new DateTime(1980, 5, 12)];
                Console.WriteLine("Didn't get expected exception");
            }
            catch (ArgumentOutOfRangeException)
            {

            }

            try
            {
                item = data["Chicago", new DateTime(1980, 5, 12)];
                Console.WriteLine("Didn't get expected exception");
            }
            catch (ArgumentOutOfRangeException)
            {

            }
        }
Пример #2
0
            public Page(int startingIndex, int length)
            {
                this.startingIndex = startingIndex;
                this.length = length;
                lastAccess = DateTime.Now;

                // This stays as random stuff:
                var generator = new Random();
                for(int i=0; i < length; i++)
                {
                    var m = new Measurements
                    {
                        HiTemp = generator.Next(50, 95),
                        LoTemp = generator.Next(12, 49),
                        AirPressure = 28.0 + generator.NextDouble() * 4
                    };
                    pageData.Add(m);
                }
            }