Exemplo n.º 1
0
        public static void Main(string[] args)
        {
            House house = new House { Name="house"};
            Display(house);

            //UpCasting
            Stock msft = new Stock();
            Asset a = msft;
            if (a == msft)
                Console.WriteLine("Identical");

            Console.WriteLine(a.Name);
            //Console.WriteLine(a.SharesOwned); //Error

            //downcasting and as operator
            Asset asset = new Asset();
            //Stock stock = (Stock)asset; // this will fail at runtime
            Stock stock = asset as Stock; // this will not fail but return null and will not give actual casting error
            if (stock !=  null)
                Console.WriteLine(stock);
            else
                Console.WriteLine("stock object is null");

            //is operator
            if (asset is Stock)
                Console.WriteLine("a is stock");
            else
                Console.WriteLine("a is not stock");

            //virtual

            Console.Read();
        }
Exemplo n.º 2
0
        public List<Stock> SelectGold13Fork34()
        {
            var ret = new List<Stock>();
            foreach (var sinfo in stockInfos)
            {
                var aStock = new Stock(sinfo);

                //取出5点
                var MA13s = aStock.MAForDay(13);
                var MA34s = aStock.MAForDay(34);

                //1点
                var ma13 = MA13s.FirstOrDefault();
                var ma34 = MA34s.FirstOrDefault();

                //2点
                var ma13_1 = MA13s.Skip(1).FirstOrDefault();
                var ma34_1 = MA34s.Skip(1).FirstOrDefault();

                if (ma13_1 < ma34_1 && ma13 > ma34)
                    ret.Add(aStock);
            }

            return ret;
        }
Exemplo n.º 3
0
        public List<Stock> SelectGold5Fork40()
        {            
            var ret = new List<Stock>();
            foreach (var sinfo in stockInfos)
            {
                var aStock = new Stock(sinfo);

                //取出5点
                var MA5s = aStock.MAForWeek(5);
                var MA40s = aStock.MAForWeek(40);

                //1点
                var ma5 = MA5s.FirstOrDefault();
                var ma40 = MA40s.FirstOrDefault();

                //2点
                var ma5_1 = MA5s.Skip(1).FirstOrDefault();
                var ma40_1 = MA40s.Skip(1).FirstOrDefault();

                if (ma5_1 < ma40_1 && ma5 > ma40)
                    ret.Add(aStock);
            }

            return ret;
        }
Exemplo n.º 4
0
 public void GetMA5()
 {
     var aStock = new Stock(stock603969);
     var val = aStock.MAForDay(5);
     Assert.AreEqual(12.84m, Math.Round(val[0], 2));
     Assert.AreEqual(12.68M, Math.Round(val[1], 2));
     Assert.AreEqual(12.42m, Math.Round(val[2], 2));
 }
Exemplo n.º 5
0
        public void GetRealTimeStockTest()
        {
            var aStock = new Stock(stock603969);
            var da = aStock.GetRealTimeInfo();

            Assert.IsNotNull(da);
            Assert.AreEqual(stock603969.Symbol, da.symbol);
            Assert.AreEqual(StockType.SH.ToString(), da.type);
        }
Exemplo n.º 6
0
 public void GetMA5ForWeek()
 {
     var aStock = new Stock(stock603969);
     var val = aStock.MAForWeek(5);
     Assert.AreEqual(13.77m, Math.Round(val[0], 2));
     Assert.AreEqual(15.13M, Math.Round(val[1], 2));
     Assert.AreEqual(16.45m, Math.Round(val[2], 2));
     Assert.AreEqual(17.34m, Math.Round(val[3], 2));
 }
Exemplo n.º 7
0
 public void GetMA181()
 {
     var aStock = new Stock(stock603969);
     var val = aStock.MAForDay(181);
     Assert.AreEqual(19.73m, Math.Round(val[0], 2));
 }
Exemplo n.º 8
0
 public void GetMA20()
 {
     var aStock = new Stock(stock603969);
     var val = aStock.MAForDay(20);
     Assert.AreEqual(13.36m, Math.Round(val[0], 2));
 }
Exemplo n.º 9
0
 public void GetMa20ForWeek()
 {
     var aStock = new Stock(stock603969);
     var val = aStock.MAForWeek(19);
     Assert.AreEqual(16.56M, Math.Round(val[0], 2));
 }
Exemplo n.º 10
0
 public void GetMa40ForWeek()
 {
     var aStock = new Stock(stock603969);
     var val = aStock.MAForWeek(40);
     Assert.AreEqual(19.84M, Math.Round(val[0], 2));
     Assert.AreEqual(20.36M, Math.Round(val[1], 2));
     Assert.AreEqual(20.90M, Math.Round(val[2], 2));
     Assert.AreEqual(21.46M, Math.Round(val[3], 2));
     Assert.AreEqual(21.91M, Math.Round(val[4], 2));
 }
Exemplo n.º 11
0
        public List<Stock> SelectAbove181()
        {
            var ret = new List<Stock>();
            foreach (var info in stockInfos)
            {
                var aStock = new Stock(info);

                // 181's line
                var ma181s = aStock.MAForDay(181);
                var ma181 = ma181s.FirstOrDefault();

                var T = aStock.GetRealTimeInfo();
                var p = 0M;
                decimal.TryParse(T.price, out p);

                if (ma181 > 0 && p > ma181)
                    ret.Add(aStock);
            }
            return ret;
        }
Exemplo n.º 12
0
        public static void Main(string[] args)
        {
            Stock stock = new Stock { Name = "hdfc", SharesOwned = 100 };
            House house = new House { Name = "bac", Mortgage = 100};

            Overrider overrider = new Overrider();
            BaseClass b = overrider;
            b.Foo();
            overrider.Foo();

            Hider hider = new Hider();
            BaseClass b2 = hider;
            hider.Foo();
            b2.Foo();

            Console.Read();
        }